【问题标题】:"Parfor" : Subscripted assignment dimension mismatch“Parfor”:下标分配维度不匹配
【发布时间】:2016-09-23 20:07:58
【问题描述】:

拜托,我写了下面的代码,它运行良好,但大约需要 6 个小时。所以有人建议我使用parfor 来减少时间。但是后来我遇到了错误“下标分配维度不匹配”,并且没有立即出现;这需要 2 个小时,然后我在完成所有迭代次数后收到错误消息。

非常感谢您的支持!顺便说一句,我只是放了parfor ind1=1:720;而不是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;

【问题讨论】:

  • 请编辑您的代码(放在代码标签中)。
  • 什么意思?我第一次用这个

标签: matlab dimension mismatch parfor


【解决方案1】:

每当您使用循环时,建议您预先分配任何可能会在循环中将其大小更改为最终大小的变量。如果你想使用parfor,那么你必须预先分配len_RSlen_QS,就像你为RS_s0所做的那样,这肯定会减少这段代码的运行时间。它还可以解决“尺寸不匹配”的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 2013-07-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多