I had write the function for find the difference of maximum and minimum from each martix row and express it as matrix .

조회 수: 8 (최근 30일)
function [mmr mmm]= minimax (A)
mmr=[abs(max(A(1:end,:))-min(A(1:end,:)))]
%mmr=[abs((max(A(1,:))-min(A(1,:)))),abs((max(A(2,:))-min(A(2,:)))),abs((max(A(3,:))-min(A(3,:))))]
mmm=abs(max(A(:))-min(A(:)))
end
code call
A=rand(100,3,4)
It return the difference between maximum and minimum value of colum but i want row.And it display two times ans

답변 (1개)

Rik
Rik 2020년 5월 22일
If you want a column instead of a row, why not transpose? And if you want both outputs, you will have to use a syntax with two outputs. If you want to suppress the output in your function you should look at the orange line underneath your code: mlint is warning you that you might have forgotten a semicolon.
And why are you taking the absolute value of when computing the maximum value?
%Note: this only fixes the main issues in the function you posted, it doesn't give the correct result for your assignment
A=rand(100,3,4);
[mmr,mmm]= minimax (A)
function [mmr,mmm]= minimax (A)
mmr=(abs(max(A(1:end,:))-min(A(1:end,:)))).';
mmm=abs(max(A(:))-min(A(:))).';
end
  댓글 수: 8
Rik
Rik 2020년 5월 22일
The difference will always be 0 or positive for real numbers, right?
Since max and min use the magnitude, this even holds for complex values.

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

카테고리

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