Pass a value from callback function in GUI to an element of vector in Workspace !

Hi. I have written a GUI without GUIDE. it first reads an image and some point from the main script and I want it to assign a value to each point.
in my gui, I iteratively ask the user to push two buttons based on the picture he sees. Pushing the button, I want a value (1 or 2) to be stored in my main (not GUI) workspace in the "label" vector.
I first tried to store all the values in one vector in GUI ("labelVector") workspace and then pass it to the base workspace: (for some reasons I had to define the i as a global variable)
function falsePositive_Callback(hobject, ~, labelVector)
global i
labelVector(i)=1;
i=i+1;
end
the problem is that with this code everything is good before the end of the function. when the callback function ends, the value comes back to 0.
In the second attemps, in the callback function I used the function:
evalin('base','label(i)=1');
to instantly pass the variable that I want to the label vector in the 'base' workspace.
At this time, the problem is that only the first value changes to 1 and no matter how many iterations I push the button, only the first values changes.
can anyone address me through my problem? Thanks.

3 comentarios

People usually use assignin for this type of thing, although the first question I would have is why you want the variable in your base workspace rather than your GUI workspace. I have never encountered a situation in my work in which this is desirable.
*assignin * can be used for a single variable. not a vector.
because I have my main code, in the middle, a gui will run and askthe user for the information(labels), it stores the information and the code will be continues based on the new information received from the user.
I'm not able to test this right now, but you might try
evalin('base','label(end+1)=1');
This should always append the value to the end of the list and doesn't require your global indexing variable.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Centro de ayuda y File Exchange.

Preguntada:

el 17 de Mayo de 2016

Comentada:

el 17 de Mayo de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by