"???In an assignment A(I) = B, the number of elements in B and I must be the same."
1 回表示 (過去 30 日間)
古いコメントを表示
I have two matrix A & B. Matrix A size 1x1013 double and matrix B size 1x12931 double. I want to convert each element of matrix A into base-N from matrix B. For example, first element of matrix A converted into first element of matrix B, second element of matrix A converted into second element of matrix B, and so on.
mm = length(A);
nn = length(B);
base = cell(1,mm);
for ff = 1:mm;
x(ff) = dec2base(A(ff),B(ff));
base{ff} = x;
end
I got error:
???In an assignment A(I) = B, the number of elements in B and I must be the same."
How to fix it? Thank you.
0 件のコメント
回答 (1 件)
Image Analyst
2013 年 2 月 9 日
編集済み: Image Analyst
2013 年 2 月 9 日
Use these lines:
for ff = 1:mm
x(ff) = str2double(dec2base(A(ff),B(ff)));
base{ff} = x(ff);
end
the issue was dec2base was returning a character string, not a number.
5 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!