create a struct with empty structs for storing plot handles
4 次查看(过去 30 天)
显示 更早的评论
Hi
I am trying to find a way of organising 4 plot and subplot handles as they are being used in a timer and need to be persistent, and I thought it might be nicer to have them in a struct so its more organised. But I am having trouble with creating the empty struct so I can add the handles in later. Is it possible or do I just need to have lots of variables floating around?
pltHandles = struct('pltHan1', [], 'pltHan2', [], 'plot1', [], 'plot2', []);
pltHandles.pltHan1 = subplot(2,2,1);
pltHandles.pltHan2 = subplot(2,2,2);
pltHandles.plot1 = plot(pltHandles.pltHan1, xdat, ydat);
pltHandles.plot2 = plot(pltHandles.pltHan2,xdat, ydat);
I also have been trying another approach using guihandles, but something is going wrong there too.
I initialise my plot with this:
fig = figure('CloseRequestFcn',@my_closereq, 'Tag', 'fig');
pltHandles.pltHan1 = subplot(2,2,1, 'Tag', 'pltHan1');
pltHandles.pltHan2 = subplot(2,2,2, 'Tag', 'pltHan2');
pltHandles.pltHan3 = subplot(2,2,3, 'Tag', 'pltHan3');
pltHandles.pltHan4 = subplot(2,2,4, 'Tag', 'pltHan4');
guidata(fig, pltHandles);
Then in another (nested) function (a timer callback), I create the plots once:
pltHandles = guidata(fig);
pltHandles.plot1 = plot(pltHandles.pltHan1, dat1, dat2, 'Tag', 'plot1');
etc
But this is where I am getting an error: Struct contents reference from a non-struct array object. This reference: pltHandles.pltHan1 in this call to plot are causing the error: plot(pltHandles.pltHan1, dat1, dat2, 'Tag', 'plot1').
Even using persistent variables that are not stored in anything for the handles, that call to plot keeps producing the same error. I have no idea what is causing this. I even got that error by omitting the handle for the subplot and calling it directly underneath the subplot line (plot1 = plot(dat1, dat2, 'Tag', 'plot1'))
I discovered the problem was one of the data coordinates was throwing the error.
2 个评论
Adam
2016-5-10
What exactly is the problem? The code you posted stores axes and plot handles in a struct. What aspect of it is not what you want?
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!