Not enough input arguments. Error in get_Result (line 6) if(answers​{i}.charAt​(j)==corre​ct.charAt(​j))

function[count]=get_Result(answers,correct)
count=[0 0 0 0 0];
for i=1:5
for j=1:5
if(answers{i}.charAt(j)==correct.charAt(j))
count(i)=count(i)+1;
end
end
end disp('the answers are: ',count);
end
anyone can help me this function. this function can compare between each character of string in a cell with a string and return a vector of number matches.
for eg.we have {'ttfft','tttff','tftft','ttfft,'fffff'} and we have a string 'ttftf'

回答 (1 件)

Rajanya
Rajanya 2025 年 3 月 19 日
'charAt' method is not available in MATLAB (it's a Java method!).
As I understand from the code, the function attempts to check the number of character matches in every string of the cell array 'answers' with 'correct'. To extract the character at a particular position of a string, you can just index the string with the required position [1-indexed] using parantheses () - see here.
Thus, the changed 'if' check would be like this -
if(answers{i}(j)==correct(j))
...
end
Thanks.

カテゴリ

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

質問済み:

2017 年 4 月 15 日

回答済み:

2025 年 3 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by