what am i getting a syntax error when i run this code?
3 次查看(过去 30 天)
显示 更早的评论
function [mmr,mmm] =minimax (M)
mmr = abs (max(M(1:end)- min(M(1:end))))
mmm = max (M:)-min(M:)
1 个评论
Marcel
2022-11-8
When changing the code to this i get the following output
function [mmr,mmm] =minimax (M)
mmr = abs (max(M(1:end)- min(M(1:end))))
mmm = max (M(:))-min(M(:))
Not enough input arguments.
Error in test (line 3)
mmr = abs (max(M(1:end)- min(M(1:end))))
回答(1 个)
Marcel
2022-11-8
编辑:Marcel
2022-11-8
Okay so after using this code
function [mmr,mmm] = minimax (M)
mmr = abs( max(M(:)) - min(M(:)) );
mmm = max(M(:)) - min(M(:));
end
and calling it in the live editor as followed
>> test 10
i receive this following output
>> test 10
mmr =
1
mmm =
1
ans =
1
I dont know what this code is supposed to do but its not throwing any error anymore
5 个评论
Steven Lord
2022-11-8
and calling it in the live editor as followed
>> test 10
i receive this following output ... I dont know what this code is supposed to do
That line of code is equivalent to passing '10' (a char vector) into your test function not 10 (the number) into it. In ASCII characters '0' and '1' are adjacent, so '1' - '0' is 1. [This makes a nice way to convert the text representation of a number into a vector containing its digits.]
one = '1' - '0'
x = '0123456789' - '0'
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!