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

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.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2020년 3월 9일

편집:

2020년 3월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by