필터 지우기
필터 지우기

Converting cell data to a matrix

조회 수: 1 (최근 30일)
charles atlas
charles atlas 2011년 11월 18일
I have one column of cell data in Matlab that reads the following:
11:32:44.69 InAir 0.00 Steady 0.00 -1.06 0.00 1.00
11:32:44.694 InAir 0.00 Steady 0.00 -0.34 0.00 0.93
11:32:44.694 InAir 0.00 Steady 0.00 -0.58 0.00 1.01
Etc.
The actual code goes on for thousands of rows. My following code reads this data in from a file: X= importdata('file1.txt'); A=(1:1:7); X(A,:)=[]; %gets rid of the first 7 lines of headers
How do I convert this one column of cell data into multiple columns with time, “inAir”, 0.00, “steady”, etc?

채택된 답변

Walter Roberson
Walter Roberson 2011년 11월 18일
regexp(X, ' ', 'split')
I would suggest, though, that instead you use
fid = fopen('file1.txt','rt');
X = textscan(fid,'%s%s%f%s%f%f%f%f','HeaderLines',7);
close(fid);
Then, X{1} will be the first column, X{2} will be the second, and so on.
  댓글 수: 1
charles atlas
charles atlas 2011년 11월 18일
That second code worked perfectly. Thank you so much

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by