I had write the function for find the difference of maximum and minimum from each martix row and express it as matrix .
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Rik
am 22 Mai 2020
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 Kommentare
Rik
am 22 Mai 2020
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.
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!