Matlab Error Message?

8 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by