Assigning data to my image in GUI

5 views (last 30 days)
Hye. I currently having a problem with function in GUI. I have a set of 3D images and a set of the data in a table in matlab workspace. May i know how should i assign/link my image to the data in the table. As example:
My GUI consist of button browse and when i browse the image, i want the image to be assign to the data in the table. the data is arrange categorically. So, means when i choose image A, the image will be link to a row of data in the table where the subject name is label A.
Im not sure how to do this as this is my first time doing GUI. Hope you guys can help me out to resolve my issue. Any help will be very appreciated to me. Thank you so much.

Accepted Answer

Ameer Hamza
Ameer Hamza on 9 May 2018
The correct way of doing it is to pass table from base workspace to the app as an input argument. In the Code View, In the top bar click add input arguments and type a name of the input argument (remember it can be any name, not necessary to be the name of your table). In this example, I suppose you named it inputTable. It is similar to adding a new input to a defined function. Next, you need to do two things
1) Pass the variable to the app:
During testing, you can pass the table to the app by pressing down arrow under Run button and typing the name of a table (this name should much the name of the table in the workspace).
If you are running the app directly, you can pass the input from command window as follow:
yourAppName(yourTable);
2) How to make the table accessible to all functions in your app
Create a public property by clicking the down arrow under Property button on the top bar in Code View. Give any suitable name to the property (in this example I suppose you named it appTable). In the startupFcn of your app, assign the inputTable to the public property appTable using the following syntax
app.appTable = inputTable;
Now you can access the table in any function of your App by referring it as app.appTable.
*************
You can directly access the variables from base workspace inside app designer without going through all of the above by using evalin(). Run the following lines in any function in ehich you want to access the table value
appTable = evalin('base', 'yourTable');
and then use appTable to access table value. But this method is not recommended. See why: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
  7 Comments
Ameer Hamza
Ameer Hamza on 9 May 2018
@Jan, Thanks. I always found that just telling about evalin() is not good. Although it is easy but it promote bad coding practices. But still telling as an extra option might be helpful for someone.
Nurul Atifah
Nurul Atifah on 9 May 2018
Edited: Nurul Atifah on 9 May 2018
Okay, so basically, im now currently want to test my data with my trained data. Before this to train my data, the data i used is in .txt and in form of x,y,z.
For GUI, i will browse the picture in .bmp. After that, it will display on my GUI. So, i want my picture to link/assign to the data point which i had used to trained it. The data is already load and save in the workspace.
Later, when i click my process button, it will perform the classification using my trained data (RF method) which resulting in getting a pair match of the image.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!