String in matrix for loop

I have created the below for loop. The txt files are all composed by 16 elements, the first 8 are string and the seconde 8 are number and are separated by comma. At the moment I created a matrix with only the last 8 value. Is it possible also to create a matrix (no structure, no array) with also the first 8 string?
fileList = dir( '*.txt' );
for i = 1 : numel(fileList)
nameFile{i} = fileList(i,1).name;
NAME = char(nameFile(i) );
fid = fopen( NAME );
val = textscan( fid, '%s', 'delimiter', ',' );
fclose( fid );
if val{1,1}{5,1} == 'LIMA' | val{1,1}{6,1} == 'VOCI'
% for jj = 1 : 7
% VAL (i,jj)= char(val{1,1}{jj,1});
% end
for j = 8 : size( val{1,1},1 )
A(i, j) = str2num( val{1,1}{j,1} );
end
end
end

댓글 수: 2

TAB
TAB 2011년 10월 25일
(no structure, no array).
What about cell array ?
Maurizio
Maurizio 2011년 10월 25일
Tabrez the values on the *.txt are for example:
A6,ANB,AUG23,204704,OMDC,VOCI,0404,0790,0468,05330,01420,14800,08550,0780
and I have n*file txt.
I need to create a for loop that each collect this 14 values and create a matrix with 14 columns and n rows.
Thanks a lot

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

답변 (1개)

Daniel Shub
Daniel Shub 2011년 10월 25일

0 개 추천

It really depends on what data type you are willing to allow. You say no structure and no array. MATLAB only deals with arrays; scalars are arrays with a length of 1. It seems like you also do not want cell arrays, since your data from textscan is a cell array.

댓글 수: 6

Maurizio
Maurizio 2011년 10월 25일
Daniel the values on the *.txt are for example:
A6,ANB,AUG23,204704,OMDC,VOCI,0404,0790,0468,05330,01420,14800,08550,0780
and I have n*file txt.
I need to create a for loop that each collect this 14 values and create a matrix with 14 columns and n rows.
Thanks a lot
Daniel Shub
Daniel Shub 2011년 10월 25일
Isn't that exactly what val{1,1} is? Do you want A = val{1,1}? Then the size(A) should be 14x1.
Maurizio
Maurizio 2011년 10월 25일
the problem that I need to create a matrix on val{1,1} i have the first file, on val{1,2} the second file and so on. What I need to create is a matrix with for example on M(1,1) the value val{1,1}{1,1}, on M(1,2) the value val{1,1}{2,1}...
Is it possible?
Daniel Shub
Daniel Shub 2011년 10월 25일
If you are trying to avoid having M be a cell array, then there is no easy way to do it. If you are trying to have M be a rotated version of val, then M = rot90(val{1,1}, 3) will do it.
Maurizio
Maurizio 2011년 10월 25일
What i'm trying to do is to collect n-time these 14 variable
A6,ANB,AUG23,204704,OMDC,VOCI,0404,0790,0468,05330,01420,14800,08550,0780
that are on txt file and create a matrix of n*14.
Maurizio
Maurizio 2011년 10월 25일
n-time because I have n txt file

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2011년 10월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by