"Parfor" : Subscripted assignment dimension mismatch

Hello
Please, I wrote a code and its works perfectly but it takes about 6 hours, so I suggest to use parfor to reduce the time, then I face the error "Subscripted assignment dimension mismatch" and it doesn't appear immediately, it takes2 hours then I got the error message after finishing all the iteration number.
So I would greatly appreciate your support!!
by the way I just put parfor ind1=1:720; instead of for !!!!
================================================
lon_rs=(reshape(l2aRS.clon_RS,3560*2000,1));
lat_rs=(reshape(l2aRS.clat_RS,3560*2000,1));
RSsig0=(reshape(l2aRS.sig0_RS,3560*2000,1));
RS_s0=zeros(720,360);
QS_s0=zeros(720,360);
I=ceil(2*(lon_rs));
J=ceil(2*(lat_rs+90));
K=ceil(2*(l1cQS.clon_QS));
L=ceil(2*(l1cQS.clat_QS+90));
for ind1=1:720;
ind1
for ind2=1:360;
indsRS=find((I==ind1) &(J==ind2) &(RSsig0~=0));
len_temp1=length(indsRS);
if (len_temp1>0);
len_RS(ind1,ind2)=len_temp1;
RS_s0(ind1,ind2)=median(RSsig0(indsRS));
end;
indsQS=find((K==ind1) &(L==ind2) &(l1cQS.sig_QS~=0));
len_temp2=length(indsQS);
if (len_temp2>0);
len_QS(ind1,ind2)=len_temp2;
QS_s0(ind1,ind2)=median(l1cQS.sig_QS(indsQS));
end;
end;
end;
=============================

4 Commenti

Without the data to test with, and without a copy of the complete error message that shows where the error occurred, it would be time consumning to answer.
Ali Alsabbagh
Ali Alsabbagh il 4 Lug 2016
Modificato: Ali Alsabbagh il 4 Lug 2016
Sir...no line number mentioned as error "this is the problem", and the error appears after 2 running hours
"Without the data to test with, and without a copy of the complete error message that shows where the error occurred, it would be time consumning to answer."
As in I would have to study the code to find all the ways that it could possibly fail and report them all back. And then you will tell me that No, this way and that way cannot have happened because your data does happen to be one of the ways that I suggested could be a problem. And I would have wasted a lot of time, completely unnecessarily.
Have you considered, by the way, putting in a bunch of try/catch statements in your code to isolate which section of the code your error is occurring on, and reporting on the value of the indices when the error occurs?
Appreciate your answer.....Yes I did and the section is parfor line.
about the data you can use at the beginning
l2aRS.clon_RS=rand(3560,2000);
l2aRS.clat_RS=rand(3560,2000);
l2aRS.sig0_RS=rand(3560,2000);
l1cQS.sig_QS=rand(11240,1);
l1cQS.clon_QS=rand(11240,1);
l1cQS.clat_QS=rand(11240,1);

Accedi per commentare.

 Risposta accettata

I was able to reproduce this, but even with a lot of debugging statements thrown in I was not able to find any particular line it was happening on. However, along the way I found a work-around:
Remember to pre-allocate your len_QS and len_RS output arrays.
By the way, you can improve the performance. Instead of looping ind1=1:720, calculate
maxiter = max(max(I), max(K));
parfor ind1 = 1 : maxiter
In your code it is not possible for any values to be stored when ind1 is greater than all of the I and all of the K values. With data values up to 1, the maximum K value is 2*(1+90) = 182, which could cut down the iterations a lot. If your input values are as large as 270 then, yes, you could get as high as 720 (higher if you accidentally have some values higher than 270), but it would probably still be worth putting in because your data will probably not always be full range.
You can do a similar calculation to limit the range for your inner loop, ind2.
Also it appears to me that you can probably vectorize you inner loop, but I would need to re-check that when I am more awake.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by