How to sort data once it is read into matlab
이전 댓글 표시
I am trying to sort the attached file first by column 1, then by column 3. I have tried the following code:
fid = fopen(filename);
data = textscan(fid, '%s %f %f');
fclose(fid);
matrix_data = [data{:}];
sort_data = sortrows(matrix_data, [1,3]);
This tells me that CAT arguments dimensions are not consistent.
Could someone tell me what is wrong with this code?
Thanks.
댓글 수: 1
Azzi Abdelmalek
2013년 10월 18일
Type
whos data
whos matrix_data
채택된 답변
추가 답변 (1개)
Vivek Selvam
2013년 10월 18일
This should solve your problem.
data = textscan(fid, '%s %s %s');
instead of
data = textscan(fid, '%s %f %f');
댓글 수: 1
Careful if you are comparing numbers which can change sign though, as this is sorting strings only:
>> sortrows( {'-88'; '-8'; '9'} )
ans =
'-8'
'-88'
'9'
카테고리
도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!