フィルターのクリア

The input function does not work well

5 ビュー (過去 30 日間)
Emilia
Emilia 2022 年 7 月 27 日
コメント済み: Emilia 2022 年 7 月 27 日
Hello,
I planned a short function but it doesn't go well, when I enter a value it is not received. Besides this function, entering a value works.
Thanks to anyone who can help me :)
Example of codes
b=[1 0 0 1 1 0];
d=sum(b.*(2.^(size(b,2)-1:-1:0)),2)
d =
38
This function is not well received
function d =binary_to_decimal(b)
Number_Bits=length(b);
if Number_Bits>10
error('A number of bits greater than 10 entered, it cannot be resolved to a decimal base')
else
d=sum(b.*(2.^(size(b,2)-1:-1:0)),2);
end
end
> binary_to_decimal(1 0 0 1 1 0)
binary_to_decimal(1 0 0 1 1 0)
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax
error. To construct matrices, use brackets instead of parentheses.

採用された回答

James Tursa
James Tursa 2022 年 7 月 27 日
Pass in a vector using the square brackets. E.g.,
binary_to_decimal([1 0 0 1 1 0])
  1 件のコメント
Emilia
Emilia 2022 年 7 月 27 日
Thank you! I am new and studying in Matlab

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by