How can i update data in the figure window in MATLAB GUI using pushbutton callback?

I have MATLAB GUI, which plots data in figure using pushbutton callback
Even though the figure window is updating the data for every iteration inside the for loop, it is not able to hold and display the data from previous iteration of the for loop.
I have tried 'hold on' option but it does not work for the GUI case
How can i fix it.

6 个评论

You can try to use guidata or setappdata/getappdata function to store figure/plot information and each time you clicked button you can plot it again.
'Does not work' is a poor description of the problem. Without having seen your code either it is unlikely that someone will find your error.
I have tried guidata(hObject,handles), but no change, it erases the previous plot after every iteration.
guidata does not have anything to do with plots being erased . plots get erased if hold on is not in effect or if there is a cla or clf
there is no cla, clf in the loop, the code structure is shown below
for i = 1: N
...
for j = 1 :X
...
...
...
end
semilogx(...)
end

请先登录,再进行评论。

 采纳的回答

Instead of hold on prefer to create the axes with the wanted "accumulation" flag directly:
axes('NextPlot', 'add')
Now new line objects created by plot() do not replace the existing contents, but are added. Do this before the loop.
Does this help already?

1 个评论

okay, found the solution myself from mathworks help documentation,
use hold(ax,'on') after the plot i.e.
for i = 1: N
...
for j = 1 :X
...
...
...
end
semilogx(...)
hold(ax,'on')
end
and it works fine, Thanks anyway for the response

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品

提问:

2018-11-23

编辑:

2018-11-26

Community Treasure Hunt

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

Start Hunting!

Translated by