Hello Community, please I've a table consisting of numbers, I want to sort column 2 in any order(ascending or decending). I've attached a picture of my table to this question.

2 件のコメント

Guillaume
Guillaume 2018 年 10 月 8 日
Please do not ask the same question multiple time. It's a waste of our effort.
Isaac Osei Agyemang
Isaac Osei Agyemang 2018 年 10 月 9 日
My mistake, sorry, thought the first post didn't get through. My apologies.

サインインしてコメントする。

 採用された回答

ANKUR KUMAR
ANKUR KUMAR 2018 年 10 月 8 日

2 投票

I am giving an example to explain.
clc
clear
load patients
T = table(Gender,Age,Height,Weight,Smoker,Systolic,Diastolic);
If you wish to sort Age out of table, then use
sort(T.Age,'ascend');
Attach you .mat file to get more clarification.

8 件のコメント

Isaac Osei Agyemang
Isaac Osei Agyemang 2018 年 10 月 8 日
the problem is my table don't have table titles, so I can do what you have suggested
ANKUR KUMAR
ANKUR KUMAR 2018 年 10 月 8 日
Attach the mat file.
Isaac Osei Agyemang
Isaac Osei Agyemang 2018 年 10 月 8 日
I want to sort the columns in the cell graphs{1,1}.Edges
Isaac Osei Agyemang
Isaac Osei Agyemang 2018 年 10 月 8 日
with the cell named as edges, its easy to sort the columns i want by writing this sort(edges{1,1}). But the other cell 'graphs' is a bit different
ANKUR KUMAR
ANKUR KUMAR 2018 年 10 月 8 日
編集済み: ANKUR KUMAR 2018 年 10 月 8 日
"I want to sort column 2 in any order". Here you refer.
AA=str2double(graphs{1,1}.Edges.EndNodes);
sort(AA(:,2));
Isaac Osei Agyemang
Isaac Osei Agyemang 2018 年 10 月 8 日
Thanks, i tried it but it doesn't completely solve my problem. I want AA to be a cell so i can copy it back to graphs{1,1}.Edges and plot my graph. I've have attached a picture to it, You can see that variable AA is now a double and I can't copy it back to graphs{1,1}.Edges
Isaac Osei Agyemang
Isaac Osei Agyemang 2018 年 10 月 8 日
編集済み: Isaac Osei Agyemang 2018 年 10 月 8 日
Thanks, I've finally been able to do it using your codes.
AA = sort(graphs{1,1}.Edges.EndNode)
graphs{1,1}.Edges.EndNode = AA.
it works fine, Thank You very much.
Guillaume
Guillaume 2018 年 10 月 8 日
編集済み: Guillaume 2018 年 10 月 8 日
it works fine
It may appear that it does and it may give you the correct result under some circumstances. In the majority of cases, it will give a completely wrong result because sort is the wrong function to use as it will sort each column separately.
I gave you the correct solution in your other identical question, b.t.w. You should read the comments to the question there as well. Until you learn to work properly with graphs, you will run into this sort of problems.

サインインしてコメントする。

その他の回答 (1 件)

KSSV
KSSV 2018 年 10 月 8 日

0 投票

Read about sort

1 件のコメント

Isaac Osei Agyemang
Isaac Osei Agyemang 2018 年 10 月 8 日
I've read about sort, sortrow, sortcols but I'm still having problems with what i want to do.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by