live plotting inside for loop in Matlab GUI
이전 댓글 표시
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!
채택된 답변
추가 답변 (1개)
Image Analyst
2017년 4월 7일
0 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Code Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!