How do I organize my code so it works?

Hello, I have to write a function that takes a vector of single-digit integers and counts the occurrences of each digit, from 0 to 9, in the vector using a single loop. Your function should take a vector in_vector of arbitrary length, which contains single-digit integers, and return a row vector num_of_digits of length 10. Here, the k-th entry in num_of_digits should contain the number of occurrences in in_vector of digit k-1.
For example, the number of zeros in in_vector would be listed as the first entry in num_of_digits, and so on. If in_vector is [0,0,1,3,2] then num_of_digits should be [2,1,1,1,0,0,0,0,0,0].
BUT I have written it already its just not working and Im not sure why. I keep getting weird errors like: Unrecognized function or variable 'num_of_digits' or function script needs an end.

回答 (1 件)

Voss
Voss 2023 年 3 月 1 日

0 投票

"Code to call your function" should be something like:
in_vector = [0,0,1,2,3];
num_of_digits = count_digits(in_vector);
disp(num_of_digits)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

質問済み:

2023 年 3 月 1 日

回答済み:

2023 年 3 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by