Trouble: integrating Gui button with data sorting script.

2 vues (au cours des 30 derniers jours)
Vadim Kachan
Vadim Kachan le 26 Juin 2019
Commenté : Vadim Kachan le 26 Juin 2019
First the mission : I had buildt a script that works in a sequence to read data from .txt file, separate it and then develop matricies for all of the data so that later i can further analyze it.
The sequence starts with "Phase = 1" and so far ends at "Phase = 4". Then i built a gui into this script with uicontrol that will help navigate the features through the data/plots later.
At this point the script works just the way i want it.
But when i introduce load data button with a callback function that will load data by changing the workspace variable "Phase" from NaN to 1. I change the variable but nothing happens. I am assuming this is the case because the if statement that starts the sequence is at the very beginning of the script where as the callback function is at the end.
The code looks like this for the callback function
line:785> function Loaddata(hObject,eventdata)
assignin('base','Phase',1)
disp("debug")
end
% I am trying to run this part of code
line:328>
if Phase == 1
for i = 1 : length(LOG) % Finds how many "logs" are present in data sample.
if LOG(i) == LOG(1)
Length = Length+1;
end
end
if i == length(Data) % identifies that the full length of data has is known.
Phase = Phase + 1;
end
end
% if I run the script without relying on the button, it runs perfectly. Having some trouble figuring out the right approach at this point.
% I know I am changing the workspace variables for sure, but it seems like it doesn't matter because in terms of order the script is passed line 328
% by the time I can call the button callback function.
% I appreiciate the help!
  2 commentaires
Geoff Hayes
Geoff Hayes le 26 Juin 2019
Vadim - are you using GUIDE, App Designer, or programmatically creating your GUI? What is line 785? What is line 328? Are these lines in your GUI code? Please copy and paste the full callback function code so that we can see how it calls Loaddata (if that is what it is doing). You don't need to save data to the base workspace. If using GUIDE (for example) you could save data to the handles structure so that all callbacks have access to this data.
Vadim Kachan
Vadim Kachan le 26 Juin 2019
Thanks for looking into this post, I'll make sure to state the process I am using in my future posts.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 26 Juin 2019
Have the beginning of your code call some functions to create the GUI and present the first GUI screen. Then have your code call waitfor() to wait for the user to fill out the GUI and press the appropriate buttons. At the end of the callback for the "go ahead" button, arrange to trigger the condition that your code is waiting for. When the callbacks have all returned, waitfor() will detect that the condition has succeeded and will proceed to run the code.
Loaddata_handle = uicontro(....);
Loaddata_handle.UserData = nan;
[...]
waitfor(loaddata_handle, 'UserData', 1);
%do your phase 1 processing.
function Loaddata(hObject,eventdata)
set(hObject.UserData, 1)
disp("debug")
end
  3 commentaires
Vadim Kachan
Vadim Kachan le 26 Juin 2019
Modifié(e) : Vadim Kachan le 26 Juin 2019
Walter, i am having some trouble with 'set(hObject.UserData, 1)
Error using handle.handle/set
Invalid or deleted object.
Error in TEST>Loaddata (line 792)
set(hObject,UserData,1)
Error using TEST (line 319)
Error while evaluating UIControl Callback.
Vadim Kachan
Vadim Kachan le 26 Juin 2019
set(hObject,'UserData',1) fixed it

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by