Extracted data added into one column, how can data be assign into different columns
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
muhammad choudhry
il 30 Nov 2020
Commentato: Ameer Hamza
il 30 Nov 2020
Hi,
I used the code below to extract the specific column from the different csv files and merge into one csv file. What I was expecting that data will be put into the order column 1, column 2, column 3 but that is not the case instead all the columns extracted has been put into 1 column what is the way to put the extracted data into different columns. I am attaching screenshots and putting the code below.
Code:
folder = fullfile('C:','Users','muhammad','Desktop','Velocity');
files = dir( fullfile(folder, '*.csv') );
for ii = 1:length(files)
data = readmatrix(fullfile(files(ii).folder,files(ii).name), 'NumHeaderLines', 1)
res = data(:,3);
end
0 Commenti
Risposta accettata
Ameer Hamza
il 30 Nov 2020
Modificato: Ameer Hamza
il 30 Nov 2020
You can define res as matrix and fill its different columns
folder = fullfile('C:','Users','muhammad','Desktop','Velocity');
files = dir( fullfile(folder, '*.csv') );
for ii = 1:length(files)
data = readmatrix(fullfile(files(ii).folder,files(ii).name), 'NumHeaderLines', 1)
res(:,ii) = data(:,3);
end
Following version is more efficient but requires a bit of code
folder = fullfile('C:','Users','muhammad','Desktop','Velocity');
files = dir( fullfile(folder, '*.csv') );
res = cell(size(files));
for ii = 1:length(files)
data = readmatrix(fullfile(files(ii).folder,files(ii).name), 'NumHeaderLines', 1)
res{ii} = data(:,3);
end
res = [res{:}];
2 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su File Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!