create a struct with empty structs for storing plot handles

4 visualizzazioni (ultimi 30 giorni)
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 Commenti
Adam
Adam il 10 Mag 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?
Rebecca Prescott
Rebecca Prescott il 10 Mag 2016
Modificato: Rebecca Prescott il 10 Mag 2016
When I ran it I was getting an error. I think it was struct contents reference from a non array object, though it was a while ago now and I can't quite recall. But it wouldn't run. From memory, the plot line caused the error. I've tried another approach that isn't quite working either. I will update the question with it.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by