简体   繁体   English

“ Parfor”:下标的分配维度不匹配

[英]“Parfor” : Subscripted assignment dimension mismatch

Please, I wrote the code below, and it works perfectly, but it takes about 6 hours. 拜托,我在下面编写了代码,它可以完美运行,但是大约需要6个小时。 So I was suggested to use parfor to reduce the time. 因此建议我使用parfor来减少时间。 But then I faced the error "Subscripted assignment dimension mismatch", and it doesn't appear immediately; 但是后来我遇到了错误“下标的分配维度不匹配”,并且没有立即出现。 it takes 2 hours then I got the error message after finishing all the iteration numbers. 需要2个小时,然后在完成所有迭代次数后收到错误消息。

So I would greatly appreciate your support! 因此,非常感谢您的支持! By the way, I just put parfor ind1=1:720; 顺便说一句,我只是把parfor ind1=1:720; instead of for ! 代替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;

Whenever you are using a loop it is recommended that you preallocate any variables that may change their size within the loop to their final size. 每当使用循环时,建议您预先分配所有可能将循环中变量大小更改为最终大小的变量。 If you want to use parfor then you must preallocate len_RS and len_QS , like you did for RS_s0 this will surely cut the run time of this code. 如果你想使用parfor必须预先分配len_RSlen_QS ,像你这样的RS_s0这必将削减这段代码的运行时间。 It may also solve the "dimension mismatch" problem. 它还可以解决“尺寸不匹配”问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM