How to sort all the columns of a file into a single column?

조회 수: 1 (최근 30일)
aneps
aneps 2014년 4월 23일
댓글: Carlos 2014년 4월 23일
I have a data file having several columns of values. I want to sort all the columns of the file into one column. For example let us assume the data has only two columns like
1 5
2 6
3 7
4 8
I want to sort this data like
1
2
3
4
5
6
7
8
This is just an example with two columns. My original data has several columns. In that case how can I sort all the columns into a single column?

채택된 답변

Carlos
Carlos 2014년 4월 23일
Try
reshape(A,numel(A),1)
  댓글 수: 2
aneps
aneps 2014년 4월 23일
This seems to work... but I am facing a problem that when I load the file, the Matlab is loading every thing in a single row!.. For example if my data is:
Filename=
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
When I run
A=load('Filename.TXT')
Instead of loading the data (Filename) as such, the Matlab reads
A=
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Inorder to use reshape(A,numel(A),1), first the Matlab should read my file as such instead of making it a single row!
Carlos
Carlos 2014년 4월 23일
try dlmread or try
A = load('Filename.txt', '-ascii');

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 23일
out=sort(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