필터 지우기
필터 지우기

I want to ascend cell

조회 수: 1 (최근 30일)
Ahmed Hassaan
Ahmed Hassaan 2012년 6월 18일
hey , I want to ascend the rows based on a specific columns in the cell array . here's an example
The input in work space is
cellmobility{1,1}
x 4
y 2
z 1
g 3
the output i seek in work space is
cellmobility{1,1}
z 1
y 2
g 3
x 4

채택된 답변

Thomas
Thomas 2012년 6월 18일
There might be an easier way of doing this but the following should work..
a{1,1}={'x 4';'y 2';'z 1';'g 3'};
a{1,1}
p=cell2mat(a{1,1}); %convertign to mat
check=str2double(cellstr(p(:,3))); % getting col 3, i.e. the num to sort
[l,row]=sort(check); % sorting
out{1,1}=p(row,:); % reorder according to sort
out{1,1}
  댓글 수: 2
Ahmed Hassaan
Ahmed Hassaan 2012년 6월 18일
well, Its working but i was making x and y and z and g for simplicity assume these variables are numbers .,
Ahmed Hassaan
Ahmed Hassaan 2012년 6월 18일
a{1,1}=[10 4 4;5 4 2;3 4 1;2 4 3];
a{1,1}
p=(a{1,1}); %convertign to mat
check=(p(:,3)); % getting col 3, i.e. the num to sort
[l,row]=sort(check); % sorting
out{1,1}=p(row,:); % reorder according to sort
out{1,1}

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

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 6월 18일
c{1,1} = cellstr(sortrows(char(c{1,1}),3));

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by