what is the most efficient way to write multiple plots to the local drive?

5 views (last 30 days)
More than 1.5 million plots must be saved to my local drive before my deep network trained.
What is the best way to write this bunch of plots efficiently?
is there any way to write with graphics (GPU)?
here is my code.
figure('visible','off','position',[0,0,244,244]);
parfor i = 1:numel(data)
line_width = 1;
clf,hold on;axis off;
for j = 1:numLines
plot((data{i,1}(j,:)),'LineWidth',line_width);
end
imFileName = [num2str(i) '.jpeg'];
exportgraphics(gca,imFileName);
end
data is a cell with size of 1000000*1
and each cell size is 10*100
All of them need to be saved not to plotted , but it takes many days!
  2 Comments
dpb
dpb on 5 Feb 2023
"More than 1.5 million plots must be saved...."
I fail to understand why the plots would have to be saved and what possible use could be made of that many plots even if did?
What do you really need -- the x,y pairs of data inside the plots, maybe? Even if so, there has to be a much more efficient way to approach the end problem, whatever it is...
Abolfazl Nejatian
Abolfazl Nejatian on 6 Feb 2023
I am analyzing forex data using deep learning methods.
My goal is to build up network training data.
For this purpose, I have focused on one-minute candles.
At first, I started with analysis in the frequency domain, but unfortunately I did not get a good answer.
After that, I decided to use the Gaussian Regression model to smooth the past of the market in a multi-resolution manner.
the features became more separatebale for the network.
Now I want to teach these features to the network in the form of continuous images.
For this, I am using a hybrid GoogleNet - LSTM.

Sign in to comment.

Answers (2)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 5 Feb 2023
In terms of time efficiency, exportgraphics() is faster than saveas().

Walter Roberson
Walter Roberson on 5 Feb 2023
Some performance tune-ups
parfor i = 1:numel(data)
persistent fig ax lines
line_width = 1;
if isempty(fig)
fig = figure('visible','off','position',[0,0,244,244]);
ax = axes(fig);
end
cla(ax);
plot(ax, data{i}.', 'LineWidth', line_width); %plot each ROW
axis(ax, 'off');
imFileName = i + ".jpeg";
exportgraphics(ax,imFileName);
end
  1 Comment
Abolfazl Nejatian
Abolfazl Nejatian on 6 Feb 2023
Dear Walter,
Thank you for your comments.
because of the
parfor
this error arised
Error: Persistent variable declarations are not supported in
parfor-loops. For more information, see Parallel for Loops in
MATLAB, "Global and Persistent Variables".
And after that I took persistance varibale out of the loop
persistent fig ax lines
parfor i = 1:numel(data)
if isempty(fig)
fig = figure('visible','off','position',[0,0,244,244]);
ax = axes(fig);
end
cla(ax);
plot(ax, data{i}.', 'LineWidth', 1); %plot each ROW
axis(ax, 'off');
imFileName = i + ".jpeg";
exportgraphics(ax,imFileName);
end
and the error was
The temporary variable 'fig' must be set before it is used. For more
information, see Parallel for Loops in MATLAB, "Uninitialized
Temporaries".
then i try this situation
persistent fig ax lines
if isempty(fig)
fig = figure('visible','off','position',[0,0,244,244]);
ax = axes(fig);
end
parfor i = 1:numel(data)
cla(ax);
plot(ax, data{i}.', 'LineWidth', 1); %plot each ROW
axis(ax, 'off');
imFileName = i + ".jpeg";
exportgraphics(ax,imFileName);
end
and the error is strange for me
Error using exportgraphics
Matrix dimensions must agree.
and the second question is although we have set the size of the figure to 244*244, this size has changed in the output images. how can handle this problem?
My sincere thanks go out to you for your assistance.

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!