In task A (:) = B, the number of elements in and B must be the same

When trying to run my code like

for ii= 1:10
   output(ii)=rand(3);
end

I get an error

In an assignment  A(:) = B, the number of elements in A and B must be the same

or

In an assignment  A(I) = B, the number of elements in B and I must be the same.

What does this error mean? What is the approach to get rid of it?

+4
source share
1 answer

This error occurs because you are trying to fill the variable part with more (or less) values ​​than its size. In other words, you have an operator A(:)=Bwhere size(A(:))differs from size(B).

rand(3) 3x3, output(ii) - ( output , output(ii) - output), , rand(3), output.

, output, , .

. , , . output=zeros(3,3,10).

for ii= 1:10
   output(:,:,ii)=rand(3);
end

output . , , . rand(ii);

for ii= 1:10
   output{ii}=rand(ii);
end

, , , , .

, , dbstop if error . , MATLAB , size(rand(ii)) size(output(ii)), .

, , .

, , , , . , , MATLAB, , .

+5

Source: https://habr.com/ru/post/1679329/


All Articles