live plotting inside for loop in Matlab GUI
Show older comments
Hi guys,
In my GUI, among many other UI controls, there are a pushbutton and an edit text. The pushbutton calculates various nonlinear optical effects, and the edittext changes one of the parameters (let's say "a") and activates the pushbutton again via the following line: myfilename('pushbutton_Callback',handles.pushbutton,[],handles);
Now what I want is to change "a" inside the pushbutton callback with a for loop, and to plot the results in live regime. I should note that I am able to individually plot the result data points after every loop, but I want to be able to connect these data points.
Here is my edittext callback that was supposed to work according to my understanding:
function a_Callback(hObject, eventdata, handles)
a = str2num(get(handles.a, 'String'));
step_a = str2num(get(handles.step_a, 'String'));
kk = 10;
for k = 1:kk
a = a + step_a;
set(handles.a, 'String', num2str(a));
myfilename('pushbutton_Callback',handles.pushbutton,[],handles);
x = handles.x;
y = handles.y;
x1(k) = x;
y1(k) = y;
axes(handles.axes1);
hold on;
plot(x1(1:k),y1(1:k));
% plot(x1(1:k),y1(1:k),'.');
hold on
drawnow
end
guidata(hObject, handles);
It seems that x and y are not updated after activating the pushbutton inside the loop. I checked this by plotting with dots (commented inside the code): it plots just the first data point and that's it.
Any help would be appreciated. Thanks!
Accepted Answer
More Answers (1)
Image Analyst
on 7 Apr 2017
0 votes
Then it appears that handles.x and handles.y are the same value each time. Why do you think that they would change? You're not doing anything that I can see to change them on each iteration. So they just stay the same.
Categories
Find more on Code Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!