フィルターのクリア

I have 26 ascii files and I want to import data from all these files with the help of a for loop and convert all of them into column vectors.

1 回表示 (過去 30 日間)
I have 26 ascii files and I want to import data from all these files with the help of a for loop and convert all of them into column vectors. I have used the following code but the workspace shows only one of these 26 ascii files converted into a column vector.Need help
%Transfer all the 26 waveforms into a directory files=dir('*.asc');
for k=1:numel(files);
B=importdata(files(k).name);
B=[B.data];
B=B(:);
end
There is no error in the code but I cannot understand why it doesnot show all the 26 column vectors after using the code.I am new to matlab so it would be great if someone can help me with it.
I also need to put all the 26 column vectors into a matrix.
Can anyone please help me correct the script

採用された回答

F.
F. 2012 年 7 月 10 日
編集済み: F. 2012 年 7 月 10 日
I suppose all files have the same number of elements
Tmp = importdata(files(k).name);
Out = zeros( numel( Tmp.data ), numel( files );
Out( :, 1 ) = Tmp.data(:);
for k = 2 : 1 : numel(files);
Tmp = importdata(files(k).name);
Out( : , k ) = Tmp.data(:);
end
  3 件のコメント
F.
F. 2012 年 7 月 10 日
% Read the first file to define the number of element
Tmp = importdata(files(1).name);
% Create the output (allocation) and fill the first column
Out = zeros( numel( Tmp.data ), numel( files );
Out( :, 1 ) = Tmp.data(:);
% All other file ...
for k = 2 : 1 : numel(files);
% import data form file
Tmp = importdata(files(k).name);
% Fill output (each column)
Out( : , k ) = Tmp.data(:);
end
Kim
Kim 2012 年 7 月 10 日
thanks.It solved my problem

サインインしてコメントする。

その他の回答 (1 件)

Oleg Komarov
Oleg Komarov 2012 年 7 月 10 日
You're overwriting B on each iteration.
I suggest to modify as follows:
for k = 1:numel(files);
B(k) = importdata(files(k).name);
end
And after the loop:
B = [B.data];

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by