How to reduce the code (csvread, reshape, concatenate matrix)?

1 回表示 (過去 30 日間)
Kong
Kong 2020 年 3 月 9 日
編集済み: the cyclist 2020 年 3 月 9 日
Hello.
I wanna reduce the below code to use several other folders. in particular, how to read files without each reading.
1. read file in the folder
2. reshape several rows to one row
3. extracting data for the same length
4. concatenate matrix
5.Add a label at the end
clear all
close all
% read file in fold
A = csvread('bend/daria_bend_geo01.csv');
B = csvread('bend/denis_bend_geo01.csv');
C = csvread('bend/eli_bend_geo01.csv');
D = csvread('bend/ido_bend_geo01.csv');
E = csvread('bend/ira_bend_geo01.csv');
F = csvread('bend/lena_bend_geo01.csv');
G = csvread('bend/lyova_bend_geo01.csv');
H = csvread('bend/moshe_bend_geo01.csv');
I = csvread('bend/shahar_bend_geo01.csv');
% reshape several rows to one row
A=reshape(A,[],1);
B=reshape(B,[],1);
C=reshape(C,[],1);
D=reshape(D,[],1);
E=reshape(E,[],1);
F=reshape(F,[],1);
G=reshape(G,[],1);
H=reshape(H,[],1);
I=reshape(I,[],1);
% extracting data for same length
A=A(1:1568,:);
B=B(1:1568,:);
C=C(1:1568,:);
D=D(1:1568,:);
E=E(1:1568,:);
F=F(1:1568,:);
G=G(1:1568,:);
H=H(1:1568,:);
I=I(1:1568,:);
% concatenate matrix
bend = [A.';B.';C.';D.';E.';F.';G.';H.';I.']
% Add a label at the end
0 or 1

採用された回答

the cyclist
the cyclist 2020 年 3 月 9 日
編集済み: the cyclist 2020 年 3 月 9 日
I would do something like this.
fileList = {'bend/daria_bend_geo01.csv','bend/daria_bend_geo01.csv',<etc>}
numberFiles = numel(fileList);
bend = [];
for nf = 1:numberFiles
thisFile{nf} = csvread(fileList{nf});
thisFile{nf}=reshape(thisFile{nf},[],1);
thisFile{nf}=thisFile{nf}(1:1568,:);
bend = [bend; thisFile{nf}.'];
end
I don't have access to MATLAB -- or your files! -- right now, so I might not have the syntax just right. But I hope you get the idea.
  1 件のコメント
Kong
Kong 2020 年 3 月 9 日
編集済み: Kong 2020 年 3 月 9 日
Thank you so much! I got it!!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by