Assigning data to my image in GUI

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.

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 9 de Mayo de 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 comentarios

Nurul Atifah
Nurul Atifah el 9 de Mayo de 2018
im sorry, may i know where is the "code view" in matlab? as im using matlab R2015b.
Jan
Jan el 9 de Mayo de 2018
Editada: Jan el 9 de Mayo de 2018
+1. Mentioning evalin together with its drawbacks is smart. It helps the OP to avoid a pitfall.
Nurul Atifah
Nurul Atifah el 9 de Mayo de 2018
Editada: Nurul Atifah el 9 de Mayo de 2018
okay. i had try using the evalin. but now how should i link those images that i browse and select to the data as i have quite large amount of images which around (200+). Is there any sample code that i could view so i have better understanding.
Ameer Hamza
Ameer Hamza el 9 de Mayo de 2018
Ahh!!! I just realized you just mentioned GUI in your question. My answer was specific to App Designer. Although in GUIDE you use a similar method by modifying openingFcn as shown in this answer https://www.mathworks.com/matlabcentral/answers/96523-how-do-i-modify-a-guide-generated-gui-to-accept-input-arguments.
Ameer Hamza
Ameer Hamza el 9 de Mayo de 2018
How you link them depend heavily on what you want to do with them. It is better to start a new question with more details on what you want to do to incease your chances of getting an answer.
Ameer Hamza
Ameer Hamza el 9 de Mayo de 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 el 9 de Mayo de 2018
Editada: Nurul Atifah el 9 de Mayo de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 9 de Mayo de 2018

Editada:

el 9 de Mayo de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by