How to select only one column from multiple matrices, to create a new matrix of them?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have the following problem. I have read in matlab 797 csv files, so i have created 797 matrices (2560x6). I want to select only the 5th column of each matrix, and create a new one that consists only of them (2560x797). Because of the big number of files, i cannot do that manually, so i'm looking for a loop. The names of the matrices are "acc_00001","acc_00002",...,"acc_00797". What should i do?? Any help?? Thank you in advance!
0 commentaires
Réponse acceptée
Junaid
le 30 Avr 2013
this should work
str = 'acc_';
index = 1;
final = zeros(2560,797); % declare your new matrix
for i=1:797
new_str = [str sprintf('%.5d',i)]; % your format like acc_00001
mat = eval(new_str); % reading your string as matrix
final(:,i) = mat(:,5); % finally copying 5th column
end
Plus de réponses (1)
Matt J
le 30 Avr 2013
Modifié(e) : Matt J
le 30 Avr 2013
It was mistake to read the files into 797 separate matrices. Redo that part, reading them all into one array, e.g.,
for ii=1:797
acc(:,:,ii)=csvread([filename num2str(ii)]);
end
then, getting the 5th columns is easy,
newmatrix=squeeze(acc(:,5,:));
0 commentaires
Voir également
Catégories
En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!