Gui Guide axes update limits

Hi I have a Gui I created using Guide.
How would I dynamically update the axes limits using a timer?
I have data being read in and displayed. The x axes limits need be set each time the data is updated when the timer calls the update
function GUIUpdate(obj,event,handles)
global x y1
handles.plot = plot(handles.axes1,x,y1);
% What I have tried...
ax = get(handles.plot,'Parent')
b.xlim([x(1) x(cols_of_data)])
axes(handles.axes1);
xlim([x(1) x(cols_of_data)])

5 件のコメント

Geoff Hayes
Geoff Hayes 2020 年 4 月 9 日
Septimus - what is cols_of_data? I suspect that is a source of an error. Also what is b? You could try just
xlim(handles.axes1, [x(1) x(end)])
assuming that x(end) is the maximum element in the array.
Rik
Rik 2020 年 4 月 9 日
You also shouldn't need the global variables.
Septimus Boshoff
Septimus Boshoff 2020 年 4 月 10 日
Thanks Geof, you're solution works.
Cols_of_data is the number of data points read in, it's a variable. Using x(end) got the idea across.
Rik I use the global variables later on in the function, I simplified the question.
Rik
Rik 2020 年 4 月 10 日
Global variables are almost always a bad idea. If you are absolutely certain you need them (you probably don't), then their names are way too short. You should be giving them very long names that include the function name. That way the chances of some other function using the same name for their global function are minimized.
Septimus Boshoff
Septimus Boshoff 2020 年 4 月 11 日
True, thanks for pointing out better coding practice.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

質問済み:

2020 年 4 月 8 日

コメント済み:

2020 年 4 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by