Sort absolute value of matrix row in descending order, display with +,- sign along with original index value
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a nXm matrix with its values from user and i want to sort only absolute values of its rows in descending order and display the original values of rows in +,- sign along with its original index value in bracket in the form of a table.
e.g
r1=[-5,-4,2,6]
ans: [6(4), -5(1), -4(2) ,2(3)]
This is the code I have written:
% generating the table of rows and columns
row = input('Enter number of rows: ');
col = input('Enter number of columns: ');
C = zeros(row ,col);
%taking values from user of matrix
for s = 1:row
for l = 1:col
str = ['Enter element in row ' num2str(s) ', col ' num2str(l) ': '];
C(s,l) = input(str);
end
end
%taking absolute values of all elements
D=abs(C);
T=array2table(D);
%sorting the rows in descending order
B = sort(T,'descend');
But I am having issues with generating index and displaying it along with brackets as mentioned in above example.
Please help me.
Thank you!!
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!