Converting Matrix to base b fails

1 回表示 (過去 30 日間)
Tom Schneider
Tom Schneider 2022 年 8 月 9 日
コメント済み: Tom Schneider 2022 年 8 月 9 日
the following code should create a multiplication table to the base b
(now in the form of multTable(7,3:10,2:3:33), i know)
when calling the function like above i get an error thrown at "table(i,ii) = a;"
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-2.
I dont know why. when using table(i,ii) = 0; the programm runs perfectly.
I always thought that dec2base only returns one value thus making filling the matrix pretty easy.
function y = multTable(b, R, C)
table = (R)' * (C);
w = width(table);
h = height(table);
for i= 1:h
for ii = 1:w
a = dec2base(table(i,ii),b);
disp(a);
disp("**")
table(i,ii) = a;
end
end
y = table;
end

採用された回答

the cyclist
the cyclist 2022 年 8 月 9 日
dec2base returns a character array representation that can be multiple characters:
dec2base(7,2) % "convert" decimal 7 to base 2
ans = '111'
  1 件のコメント
Tom Schneider
Tom Schneider 2022 年 8 月 9 日
thx for the answer ! i used str2num to finally get them into the matrix

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by