what am i getting a syntax error when i run this code?

조회 수: 7 (최근 30일)
mesfin
mesfin 2022년 11월 8일
댓글: Steven Lord 2022년 11월 8일
function [mmr,mmm] =minimax (M)
mmr = abs (max(M(1:end)- min(M(1:end))))
mmm = max (M:)-min(M:)
  댓글 수: 1
Marcel
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
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
Marcel
Marcel 2022년 11월 8일
편집: Marcel 2022년 11월 8일
idk already made a application for the company im working for and it works well so far and does the job. it may sound stupid but thats just me im a chaotic person when it comes to my mind
e.g. i know what abs does but just havent used max and min yet
Steven Lord
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'
one = 1
x = '0123456789' - '0'
x = 1×10
0 1 2 3 4 5 6 7 8 9

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by