String in matrix for loop
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Daniel Shub
2011 年 10 月 25 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!