How to reduce the code (csvread, reshape, concatenate matrix)?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!