Matlab slows downs within certain loop

1 Ansicht (letzte 30 Tage)
mootje_3000
mootje_3000 am 13 Mai 2019
Kommentiert: mootje_3000 am 14 Mai 2019
In my code I have the following loop where running my code slows down:
for i = 1:c_max
c_n = cm(i,:);
x = c{i}(:,1);
y = c{i}(:,2);
z = c{i}(:,3);
markersize = c{i}(:,4);
for j = 1:size(c{i}(:,1),1)
splot = scatter3(x(j),y(j), z(j),markersize(j), c_n);
drawnow limitrate
end
end
I know that when using "drawnow" it makes the simulation slower. However, when I'm not using it, somehow my plot and matlab do not respond anymore after the plot is shown and I have to restart matlab again. I'm also unable to save the plot because matlab does not respond anymore. Does any one have suggestions on how to make it faster and/or not make matlab unresponsive? In this case, I'm using 250k data points within each column matrix 'c' and the maximum value for 'c_max' is 25.
  13 Kommentare
Walter Roberson
Walter Roberson am 13 Mai 2019
I noticed that all items in the same i use the same color. If one scatter() object were to be used per i then the color data could be left as a 1 x 3 vector instead of having to be repmat() of that to the number of rows equal to the current number of objects.
The user has indicated that c is max 25 elements, and that each element is a matrix of up to 250k rows.
There are ways to paint all of this in bulk, but with the drawnow in there, I have to suspect that they want to view the simulation evolve.
mootje_3000
mootje_3000 am 13 Mai 2019
Bearbeitet: mootje_3000 am 13 Mai 2019
@WalterRoberson I do not need to see the display evolve, but as i explained earlier, this is the only way for matlab not to get stuck after to simulation and I'm able to save my plot.
@AdamDanz c contains groups that belong together. These groups have a different size. In order to identify these groups in the plot, I need to give them a different color. But also the size of the object within a group are not similar, that's why the size also needs to be different for every object.
@WalterRoberson c is indeed max 25 elements, but these 25 elements have together a total value of 250k data points, which varies per element. Drawing it in bulk will somehow get matlab to be unresponsive.....?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 13 Mai 2019
for i = 1:c_max
c_n = cm(i,:);
x = c{i}(:,1);
y = c{i}(:,2);
z = c{i}(:,3);
markersize = c{i}(:,4);
scatter3(x(:), y(:), z(:), markersize(:), c_n);
drawnow limitrate
end
  2 Kommentare
Walter Roberson
Walter Roberson am 14 Mai 2019
And if you need to, then
batchsize = 5000;
batchoff = 0:batchsize-1;
for i = 1:c_max
c_n = cm(i,:);
x = c{i}(:,1);
y = c{i}(:,2);
z = c{i}(:,3);
markersize = c{i}(:,4);
%ending with the last full batch and then doing the partial batch
%saves having to keep testing if we have reached the end of the data
for j = 1 : batchsize : size(c{i}(:,1),1) - batchsize + 1
scatter3(x(j+batchoff), y(j+batchoff), z(j+batchoff),markersize(j+batchoff), c_n);
drawnow limitrate
end
scatter3(x(j+batchsize:end), y(j+batchsize:end), z(j+batchsize:end), markersize(j+batchsize:end), c_n);
drawnow limitrate
end
mootje_3000
mootje_3000 am 14 Mai 2019
Thanks a lot, works like a charm! @AdamDanz also thanks for your help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by