필터 지우기
필터 지우기

Multiple Text files to Labeled matrix/array

조회 수: 1 (최근 30일)
Ronald
Ronald 2014년 8월 5일
댓글: Azzi Abdelmalek 2014년 8월 5일
Hi all,
I have multiple .txt files that I want to put into an array. The data is scrambled in the file with other objects, but the general format looks like this:
RA 5
Rz 50
Rd 45
in the next file, the format is similar but still mixed in with other objects
RA 7
Rz 15
Rd 35
I want it to output a matrix/array that is
RA Rz Rd
5 50 45
7 15 35
Here is what i have so far
For i=1:100
outputString = sprintf('SR%d', i);%file names should be SRX where X is integer
fileID=fopen('outputString');
result = textscan(fileID,'%s %d ');
J=result{1}
X=char(J)
mat_cell(:,2)=J
K=result{2}
fclose(fileID);
s = cell2struct(result,result{1},3)
I am having problems both getting the Cell Arrays into column labels, but also inputing multiple files.
Thank you!

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 8월 5일
편집: Azzi Abdelmalek 2014년 8월 5일
for k=1:100
outputString = sprintf('SR%d.txt', k);
d=importdata(outputString)
num{k}=d.data
end
  댓글 수: 2
Ronald
Ronald 2014년 8월 5일
Thank you for the help so far, those two functions were very useful. How do I now convert the cell arrays to column headers? this was one of my main issues. I have tried Char, Cell2struct and many other Cell2 commands.
Azzi Abdelmalek
Azzi Abdelmalek 2014년 8월 5일
for k=1:100
outputString = sprintf('SR%d.txt', k);
d=importdata(outputString)
num{k}=d.data'
end
out=cell2mat(num)

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


Christopher Berry
Christopher Berry 2014년 8월 5일
It sounds like you really should be using a table data type. Take a look at some of the examples on the document page here:
Its probably much better suited to what you are trying to do.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by