Join matrices in for loop

2 ビュー (過去 30 日間)
Giorgos Papakonstantinou
Giorgos Papakonstantinou 2013 年 4 月 19 日
I am importing several files in matlab which are in csv format. Each of these files has two columns. So when I import the first one I create a matrix with two columns. therefore I would like to join this 2 column matrices in one matrix. I would like to do that in a for loop.
My code is the following:
files=dir('*.csv');
Data=[];
for i=1:length(files)
fid(i)=fopen(files(i).name);
files(i).values=textscan(fid(i), '%f %f','delimiter',',','HeaderLines',20,'MultipleDelimsAsOne',1);
A=cell2mat(files(i).values);
end
In my code each time the matrix A is a two column matrix. So I would like to join all the A matrices.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 4 月 19 日
files=dir('*.csv');
A=[];
for i=1:length(files)
fid(i)=fopen(files(i).name);
files(i).values=textscan(fid(i), '%f %f','delimiter',',','HeaderLines',20,'MultipleDelimsAsOne',1);
A=[A;cell2mat(files(i).values)];
end
  1 件のコメント
Giorgos Papakonstantinou
Giorgos Papakonstantinou 2013 年 4 月 20 日
Thank you very much for the answer. It was so easy to implement....
Only one notice it should be
A=[A cell2mat(files(i).values)];
The semicolon must be removed

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by