필터 지우기
필터 지우기

Sortrows_function of a Matrix

조회 수: 1 (최근 30일)
Mark S
Mark S 2020년 3월 14일
댓글: Ameer Hamza 2020년 3월 14일
T=[1:10;40,43,18,43,34,18,23,31,44,38]';
T=ShortestTime(T)
T=LongestTime(T)
function [c]=ShortestTime(T)
c=sortrows(T,[2 1])
end
function [c]=LongestTime(T)
c=sortrows(T,[-2 1])
end
Hi, I wrote a little script to sort a matrix. But now I want that Matlab write only the first column of the matrix. How do I do that?

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 3월 14일
You can get the first column of a matrix by indexing like this
first_column = T(:,1);
  댓글 수: 2
Mark S
Mark S 2020년 3월 14일
편집: Mark S 2020년 3월 14일
Ok, thanks now it works. But when i run the script it write every time also the sortet Matrix.
But i want only that Matlab write the solution of the function: ShortestTime and LongestTime.
How can i do this?
T=[1:10;40,43,18,43,34,18,23,31,44,38]';
T=ShortestTime(T)
T=LongestTime(T)
function [c]=ShortestTime(T);
c=sortrows(T,[2 1])
ShortestTime = T(:,1)
end
function [c]=LongestTime(T)
c=sortrows(T,[-2 1])
LongestTime = T(:,1)
end
Ameer Hamza
Ameer Hamza 2020년 3월 14일
I am not sure about your question. Maybe you want to save them in different variables
T=[1:10;40,43,18,43,34,18,23,31,44,38]';
T1=ShortestTime(T);
T2=LongestTime(T);

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by