Reputation: 15
I use Matlabs plot function to create a comparison of two matrices (each 1300x1 double). The values are plotted in hundreds, because every hundred needs its own color and marker type. It looks like this:
Start=1
for i=1:1:13
plot(ArrayA(Start:Start+99,1),ArrayB(Start:Start+99,1));
Start=Start+100;
end
I left out the parameters for marker and color for readibility.
It usually works fine, but sometimes, there is a special case where ALL the values in the matrices are equal to a certain scalar value (or at least some 1000 or so are and the rest 300 are equal to some other scalar). In these cases, we can be sure that values in ArrayA are equal to values in ArrayB element-by-element.
When this happens, whole matlab fails and gives me "Matlab System Error". If you need details of this error, I am happy to provide it.
I am pretty sure this is linked to the points being equal and hence failing to plot correctly, as in other cases, it works just fine.
I would like to ask you for a suggestion for a workaround, as the solutions does not need to be very neat (as this happens very rarely).
Upvotes: 1
Views: 599
Reputation: 1
I had exactly the same issue on Matlab2010b
on Mac OS X: plotting in a loop, vector would sometimes become all NaNs
, Matlab would crash then or shortly after but not always.
Reading this thread now, I think it is very probably a race condition between different threads, so the guys from Mathworks should really fix that.
Putting a pause(0.1)
increases the probability that the other thread can finish first (it is not really a solution, though).
Race condition would also explain why it only happens once in a while, because it depends on the (random) allocation of tasks to threads etc.
Upvotes: 0
Reputation: 627
try:
pause(.1)
in the loop
OR, you can try defining 1 plot and setting the data everytime:
fig = figure;
hold on;
myplot = plot(NaN,NaN,'-')
for i = 1:100
set(myplot,'XData',X(i),'YData',Y(i))
dummy = dummy+1;
drawnow;
end
where X and Y are your respective data.
Upvotes: 0
Reputation: 599
It is very strange. 1300 of double is nothing and Matlab should be able to handle that. I just tried plotting 13000 of the same values on a figure and Matlab did not bother.
Anyhow, I am not 100% sure why Matlab crashes (maybe the full error message could be useful), but if you could be more specific about your problem you are trying to solve, we could maybe find a different solution.
Are you trying to spot the locations in your vectors where you find different values?
Upvotes: 1