I had write the function for find the difference of maximum and minimum from each martix row and express it as matrix .
2 次查看(过去 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
0 个评论
回答(1 个)
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
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 Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!