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

4 ビュー (過去 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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by