To operate a function in all rows of matrix

조회 수: 4 (최근 30일)
Rafael Zanetti
Rafael Zanetti 2019년 2월 8일
댓글: Rafael Zanetti 2019년 2월 8일
How I can repeat a function irrespective a size of matrix? For example, I have a matrix A and I want calculate the difference between maximum and minimum values in all rows, without I have determine the number of rows in my function, because I have began to set the function, but I just get the function works writtening a number of each row. Thank you!
A =
66 94 75 18
4 68 40 71
85 76 66 4

채택된 답변

Adam Danz
Adam Danz 2019년 2월 8일
편집: Adam Danz 2019년 2월 8일
The range() function computes the difference between max and min values. When the input is a matrix, it acts on the columns. To act on the rows, just transpose the matrx. I added a second transpose so the results are in a column.
maxMinDiff = range(A')'
maxMinDiff =
76
67
81
  댓글 수: 3
Adam Danz
Adam Danz 2019년 2월 8일
Oh yeah, that's better.
maxMinDiff = range(A, 2)
maxMinDiff =
76
67
81
%or
maxMinDiff = max(A,[],2) - min(A,[],2)
maxMinDiff =
76
67
81
Rafael Zanetti
Rafael Zanetti 2019년 2월 8일
I thank you, work it, I was breaking the head researching and I was not achieving, one more time, I am grateful.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by