Read a 55x55 matrix with matlab

조회 수: 2 (최근 30일)
Mélanie Ghysels-Dubois
Mélanie Ghysels-Dubois 2021년 3월 4일
댓글: dpb 2021년 3월 4일
Dear all,
I would like to read in a txt file (see attached document) the 55x55 matrix using matlab.
In the txt file, the matrix appears in a block of 9x6 followed by one line (which then accounts 55 values) . And there are 55 blocks like this.
In fact, this block contains averaging kernel values for the 55 pressure levels of the sounding instrument.
How can I read this gile so I have at the end a matrix called A which has a dimension of 55x55?
Thank you for your help,
Best regards
Mélanie

답변 (1개)

Akira Agata
Akira Agata 2021년 3월 4일
How about the following?
A = readmatrix('Averaging_kernel_MLS_v04_0N.txt');
A = reshape(A',60,[])';
A = A(:,1:55);
  댓글 수: 6
Mélanie Ghysels-Dubois
Mélanie Ghysels-Dubois 2021년 3월 4일
Yes, thank you dpb, Adding this line helped removing NaNs and to get the right matrix at the end.
Thanks a lot!
dpb
dpb 2021년 3월 4일
Both end up the same in the end...
>> B=readmatrix('Averaging_kernel_MLS_v04_0N.txt');
>> B=reshape(B.',60,[]).'; B=B(:,1:55);
>> all(A(:)==B(:))
ans =
logical
1
>>
It's just perhaps a little cleaner w/ textscan. Too bad TMW hasn't added the ability to pass a filename as alternate input besides just a file handle so could avoid having to have the encapsulating fopen...fclose pair.

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

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by