필터 지우기
필터 지우기

Import column from files

조회 수: 2 (최근 30일)
Momo
Momo 2013년 7월 12일
Hello,
I have 200 files with names starting from 3201.rad to 3396.rad, each files has header (5 lines of text), 1057 raw and 3 columns. I want to create a matrix with the second column of each file, without the header. Matrix with 1057 raw, 196 column.
Thank you in advance for your help!
M.

답변 (1개)

Matt J
Matt J 2013년 7월 12일
A=zeros(1507,196);
for i=3201:3396
filename=[num2str(i) '.raw'];
A(:,i) = dlmread(filename,'',[5,1,1511,1]);
end
  댓글 수: 2
Momo
Momo 2013년 7월 12일
Thank you Matt for your respons. However, it does not work. it gives me the message below
??? Error using ==> dlmread at 145 Mismatch between file and format string. Trouble reading number from file (row 1, field 5) ==> \n
I don't know how I can solve this problem. In details this is the data in files (4 columns, 1073 rows, 5 lines in header )
without numbers 1, 2, 3, 4, 5 in rows
  1. 3201.rad
  2. center 668.60 831.10 -> 668.14 832.82, r_max 1070.04
  3. radius binding according to
  4. 1 sectors on 360 degs with origin at -180.00 deg, 0.00 deg
  5. a I e/s n ...
  6. 0.0 102215.03 1915.55 4.6
  7. 1.0 105897.02 4812.49 9.9
  8. 2.0 108802.90 3875.25 16.4
  9. ....
  10. ..... # ......
  11. 1072.0 108802.90 3875.25 16.4
I have 196 files with this data, and I would like to tranfer only the 2nd column of all files to a matrix.
Thank you very much
Matt J
Matt J 2013년 7월 12일
편집: Matt J 2013년 7월 12일
Works fine for me, Momo. What version of MATLAB are you using and are you sure you're calling DLMREAD with 3 input arguments, like in what I posted?
The error message says it's trying to read row 1, field 5. It should not be doing that if you've called it with the 3rd argument.

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

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by