MATLAB Answers

Plotting very slow and took long time to launch plot tool

60 views (last 30 days)
Melissa Chen
Melissa Chen on 20 Jun 2018
Answered: Greg on 21 Jun 2018
I am plotting 50 graphs in the same plot with these few lines. The data are already in the workspace.
figure; hold on
for n = 1:50
plot(x, y,'LineWidth',2.0);
hold on
end
The figure window shows up within 5 seconds, but it takes MATLAB 3 minutes to populate the graph window with the graphs. Additionally, when I try to use the plot tools to modify the figure, each icon I click or each action I did takes ~ 10 seconds to act, including some simple action like moving the legend position or click to select a specific graph. My computer practically froze while waiting.
I have a pretty fast computer - an i7 8th generation with 16 GB RAM. I am running on MATLAB R2017b. Running other high memory usage program doesn't have this issue. I have never had this problem with R2017b on another supposedly slower computer - i3 with 32 GB RAM.
I am more of trying to trouble-shoot if this is the problem of the computer or with MATLAB. If anyone had similar problem with R2017b hopefully the answer I got would be helpful. Thanks MATLAB community!

  4 Comments

Show 1 older comment
Greg
Greg on 21 Jun 2018
Graphics display takes a back seat to CPU activity, and will not flush until the CPU has idle time. There are a wealth of articles that will explain this better than I am going to here. But, start with a look at the documentation for drawnow.
---Sorry, thought I saw you trying to use 50 separate figures. Above comments mostly not applicable. I'm with KSSV - if x and y are extremely large, you're going to have performance issues.
Greg
Greg on 21 Jun 2018
Also, you've already called hold on before the loop, doing it again inside is silly.
Melissa Chen
Melissa Chen on 21 Jun 2018
Thanks Greg. my x is a [1x1801] and my y is a [50 x 1801]. I did thought 50 maybe too much so I went back and try to plot 10 instead. The amount of time it takes to show up is similar to plot with 50 which is something I never seen before with my old computer. But you made a good point of the CPU activity and maybe there's something that's feeding off CPU when I am plotting with matlab.

Sign in to comment.

Answers (1)

Greg
Greg on 21 Jun 2018
Given information from your comments that y is 50x1801, the command
plot(x,y,'LineWidth',2);
Will already plot all 50 rows of y against x. Doing it inside a loop gives you 50*50 = 2500 lines in your figure.
Replace all of your code with the one line above.

  0 Comments

Sign in to comment.

Sign in to answer this question.