필터 지우기
필터 지우기

Sorted vector changing dimensions

조회 수: 1 (최근 30일)
Vinny
Vinny 2016년 4월 15일
편집: Azzi Abdelmalek 2016년 4월 15일
I have two vectors here
a=[4 2 1;9 3 5]
a=[9 8;7 6;5 4]
I'm sorting them from left to right using this code
m=numel(a);
for i=1:1:(m-1)
for j=1:1:(m-1)
if a(j)>a(j+1)
temp=a(j);
a(j)=a(j+1);
a(j+1)=temp;
end
end
end
a=a'
The code is working to sort them from smallest to biggest, from left to right. But the dimensions are now changing
4 2 1
9 3 5
to
1 2
3 4
5 9
and
9 8
7 6
5 4
to
4 5 6
7 8 9
One of you guys helps me with one thing then a new issue arises. So now how do I alter the code to show the correct sorted dimensions. Anything is appreciated. Thank you.
No built in functions, please.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 15일
편집: Azzi Abdelmalek 2016년 4월 15일
instead of a=a' use
a=reshape(a,size(a'))'

카테고리

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