create a struct with empty structs for storing plot handles
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Adam
am 10 Mai 2016
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?
Antworten (0)
Siehe auch
Kategorien
Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!