0

セル配列を再形成するときに問題が発生しています:

w = size(im,1);                                % width size
h = size(im,2);
d = size(crossfield,3);
for pxRow = 1:h % fixed pixel row
  for pxCol = 1:w % fixed pixel column
    for pxBreadth = 1:d    
      for r = 1:h % row of distant pixel
        for c = 1:w % column of distant pixel
          for z = 1:d
 
            field(c,r,z) = crossfield(c,r,z).*rmatrix(c,r,z);                
 
          end
        end
      end
    b(i) = {field}; % filling a cell array with results. read below
    i = i+1;
    end
  end
end
 
 b = reshape(b, w, h,z);

そしてエラー:

==> reshape の使用エラー

RESHAPE を行うには、要素の数を変更してはなりません。

役に立つかもしれない他の情報:

>> size(im)

ans =

    35    35

>> size(crossfield)

ans =

    35    35     3

>> size(rmatrix)

ans =

    35    35     3
>> size(w)

ans =

     1     1

どうすれば b を変形できますか?

4

1 に答える 1

1

3 つの内側のループには、次のように同じ効果があることに注意してください。

field = crossfield .* rmatrix;

3 つの外側のループは、セル配列のすべての要素をb同じ値に設定するだけです。したがって、コードは次のように簡略化できます。

[w h] = size(im);
d = size(crossfield,3);

b = cell(w,h,d);
b(:,:,:) = {crossfield .* rmatrix};
于 2012-07-03T09:11:49.183 に答える