MATLAB Answers

0

Replotting Data vs. Storing Plots/Images

Asked by Sam Gottheim on 15 Sep 2017
Latest activity Edited by Joseph Cheng
on 15 Sep 2017
I've created a GUI which allows my to read, process, and plot data with push buttons allowing me to scroll through the data (back and forth). Each time a scroll through the data it is essentially replotting the data. I'm going to be using this code to run through 100's of plots and to eventually export all of the plots as images.
My question is, which is better (faster), replotting with each button click or somehow storing the plots as images and then calling them back. And if storing the plots as images is better, how should I go about doing that?
Thanks!

  0 Comments

Sign in to comment.

1 Answer

Answer by Joseph Cheng
on 15 Sep 2017
Edited by Joseph Cheng
on 15 Sep 2017

I think the answer would be dependent on how many points are in each line and the size of the images you're going to be pulling in from the HD.
here is portions of a quick GUIDE example i generated, (recalling of the plot image is not scaled properly to make it look nice). example is just to show saving the sets of data into images (or atleast a version that is just a capture of what would have been plotted). the example guide gui if you want put it in has two buttons and one axes to display the data. the buttons are just counters that goes and loads the next image/plot
these are just the pertinent callbacks in the example GUI.
% --- Executes just before whichisfaster is made visible.
function whichisfaster_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.data = rand(1000,4,10);
handles.counter = 1;
%now to generate some dummy plot images
f = figure('visible', 'off');
for ind = 1:10
plot(rand(1000,4));
print(f, '-djpeg', ['image' num2str(ind) '.jpg'])
end
close(f)
% end of creating dummy plot images
% Update handles structure
guidata(hObject, handles);
function varargout = whichisfaster_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
tic
axes(handles.axes1)
plot(handles.data(:,:,handles.counter));
handles.counter = handles.counter+1;
if mod(handles.counter,11) == 0
handles.counter=1;
end
% Update handles structure
guidata(hObject, handles);
toc
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
tic,
axes(handles.axes1)
imagedata = imread(['image' num2str(handles.counter) '.jpg']);
image(imagedata);
handles.counter = handles.counter+1;
if mod(handles.counter,11) == 0
handles.counter=1;
end
% Update handles structure
guidata(hObject, handles);
toc
here you can see that plotting the small amount of data is much faster than loading all the points in an image and then displaying it.

  0 Comments

Sign in to comment.