Sort absolute value of matrix row in descending order, display with +,- sign along with original index value
2 次查看(过去 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!