Filter löschen
Filter löschen

Sort absolute value of matrix row in descending order, display with +,- sign along with original index value

2 Ansichten (letzte 30 Tage)
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!!

Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by