Info

This question is closed. Reopen it to edit or answer.

Need help in MATLAB GUI

1 view (last 30 days)
Sairah
Sairah on 25 Jul 2017
Closed: MATLAB Answer Bot on 20 Aug 2021
I am writting my question first time in MATLAB Central, I want to create the GUI using one push button and check box. In my GUI I read the text file in the while loop and plot the data of text file data using push button and check box. The purpose of push button plot the point plotting while the check box plots the data as trajectory When I push pushbutton so the simulation do just point plotting while hitting check box simulation performs continuous plotting from that current point. please help I spent 4 days but couldnt find the way two link the check box and push button in MATLAB GUI
I attach my code to this question

Answers (1)

Jan
Jan on 25 Jul 2017
Do not use global variables, because they make your life much harder. Globals are always a shot in your knee. Prefer storing the flag in the UserData or ApplicationData of the GUI. Search in this forum for "share data between callbacks".
line = fgetl(fid);
nums = str2num(line);
This will fail at the end of the file. Check for fgetl replying -1 before processing the data.
pause(0.0001) is meaningless, because the minimal pause is 0.01 seconds.
Use the standard code indentation to improve the readablility of the code. Ctrl-A Ctrl-I.
This does not do, what you want:
flag == 1
This compares the contents of flag with 1, but does not change its value. You mean
flag = 1;
But as said above: Do not use globals. It is easier to use the state of the checkbox itself:
while true
line = fgetl(fid);
if ~ischar(line)
break;
end
drawnow; % Give the GUI a chance to process events
checked = get(handles.checkbox1, 'Value');
if checked
...
else
...
end
end
  6 Comments
Jan
Jan on 27 Jul 2017
@Sairah: If the loop should start, when the button is pressed, insert it in the button's callback function. If the loop should start during the GUI is opened, insert it in the OpeningFcn, but then it blocks the creation of the GUI and I assume this is not wanted.
Did you see, that I've asked a question for clarification? I still do not understand what the button and the checkbox should do, so how could I suggest a solution? I've posted all my ideas about "cennecting" the loop and the contents of the checkbox already and I do not see, that you explain in any way, if my suggestions work for you or not. It looks like you ignore my contributions.

Community Treasure Hunt

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

Start Hunting!