필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Anisa
Anisa 2013년 2월 9일
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.

답변 (1개)

Image Analyst
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
Image Analyst
Image Analyst 2013년 2월 9일
Cast your A to int32 before you run the loop.
Anisa
Anisa 2013년 2월 18일
I already tried your solution, but still got the same warning. Why?
mm = length(A);
nn = length(B);
base = cell(1,mm);
x = zeros(1,mm)
for ff = 1:mm
ff
AA=A(ff)
BB=B(ff)
x(ff) = str2double(dec2base(int32(AA),int32(BB)));
base{ff} = x(ff);
end

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by