Matlab Error Message?

조회 수: 9 (최근 30일)
Ahmed
Ahmed 2016년 1월 21일
댓글: Ahmed 2016년 1월 21일
I have the below matlab code, and I got this error "Subscripted assignment dimension mismatch"
for s=1:6
x(:,s) = Cr(1,s) .* x2(:,s);
end
Cr is 1x6, x2 is 100x6?
Does anyone know where is the problem?

채택된 답변

Guillaume
Guillaume 2016년 1월 21일
Your x must have strictly more or less than 100 rows. Hence the assignment fails.
Note that a much simpler way of achieving what you want is with bsxfun:
x = bsxfun(@times, Cr, x2) %that's all that's needed. No loop.
  댓글 수: 1
Ahmed
Ahmed 2016년 1월 21일
That is fine Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2016년 1월 21일
편집: Image Analyst 2016년 1월 21일
Maybe you're after this: (????)
Cr = rand(1,6);
x2 = rand(100,6);
x = zeros(100, 6); % Preallocate
for row = 1 : size(x2, 1)
x(row, :) = Cr(1:end) .* x2(row,:);
end
x
  댓글 수: 1
Ahmed
Ahmed 2016년 1월 21일
Thank you

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by