Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store matlab plot inside a variable and reuse it

I have written a GUI application which after performing some analyses on a large dataset it offers the possibility of several plotting options over the data (through a pop-up menu).

So right now every plot is calculated on the fly upon being chosen in the pop-up menu. This is not efficient and time consuming so I would like to calculate all these plots just once, then store them somehow in variables and be able to assign each of them to the handle of the gui axes.

Basically I want to have a plot of the type h=plot([1 2 3]) stored in variable (without visualising) and be able to visualise it on demand at a later time. I tried assigning the axes handle to the plot handle e.g.

h=plot([1 2 3]);
handles.plottingscreen_axe=h; 

...but it visualises nothing. To simplify the problem I've been trying with test data on the terminal to simply assign one figure handle to another in order to somehow dump the visualisation to the other figure but nothing is working, e.g.

h=plot([1 2 3]);
f=figure;
f=h;

...but I'm not able to visualise the plot of h to figure f.

Obviously I'm not experienced with graphic handles so I imagine that this is something simple for someone who is. I haven't been able to find any related documentation about it, everybody suggests to simply make a function that replots everything but this is precisely what I'm trying to avoid.

Any help is appreciated and I apologise in the case that my question is about something too basic.

like image 237
en1 Avatar asked Dec 22 '11 14:12

en1


1 Answers

figure;
ah = axes;
hold(ah,'on');  
%Axes must have hold on or lh(1) will become invalid after lh(2) is created
lh(1) = plot(ah,[1 2 3],[1 2 3],'r','visible','off');
lh(2) = plot(ah,[1 2 3],[3 2 1],'b','visible','off');

This will turn on Line 1 (red)

set(lh(1),'visible','on');set(lh(2),'visible','off')

This will turn on Line 2 (blue)

set(lh(1),'visible','off');set(lh(2),'visible','on')

In your GUI you will need some kind of callback to cycle the visible on/off state off all your line handles. Note: If these are very large datasets and you have lots of lines it could eat up a bunch of memory.

like image 168
Aero Engy Avatar answered Sep 30 '22 13:09

Aero Engy