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

2 visualizaciones (últimos 30 días)
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

Respuestas (1)

Rik
Rik el 22 de Mayo de 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 comentarios
Rik
Rik el 22 de Mayo de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by