how to import file?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
How to import all these csv files and extract only the 3 column from all these files and plot 3 column with respect to 2nd column data
T = readtable('3ghs_datafiles.csv','NumHeaderLines',3);%i have to eliminate 1 rows which is having header names a,b, r
a=T(:,3);
T1 = readtable('3.1ghs_datafiles.csv','NumHeaderLines',3);%i have to eliminate 1 rows which is having header names a,b, r
b=T1(:,3);
T2 = readtable('3.2ghs_datafiles.csv','NumHeaderLines',3);%i have to eliminate 1 rows which is having header names a,b, r
c=T2(:,3);
T3 = readtable('3.3ghs_datafiles.csv','NumHeaderLines',3);%i have to eliminate 1 rows which is having header names a,b, r
d=T3(:,3);
T4 = readtable('3.4ghs_datafiles.csv','NumHeaderLines',3);%i have to eliminate 1 rows which is having header names a,b, r
d=T4(:,3);
xaxis=120:0.1:120.5;
Final_T=cat(a,b,c,d);%i have to collect 3rd column data from all the files and store in 1 variable
plot(xaxis,Final_T)
0 comentarios
Respuestas (2)
Les Beckham
el 16 de Nov. de 2023
You were pretty close. Here is one approach, converting your third columns to arrays instead of extracting them as tables with only one column.
Adjust as desired.
T = readtable('3ghs_datafiles.csv','NumHeaderLines',3);%i have to eliminate 1 rows which is having header names a,b, r
a = table2array(T(:,3));
T1 = readtable('3.1ghs_datafiles.csv','NumHeaderLines',3);%i have to eliminate 1 rows which is having header names a,b, r
b = table2array(T1(:,3));
T2 = readtable('3.2ghs_datafiles.csv','NumHeaderLines',3);%i have to eliminate 1 rows which is having header names a,b, r
c = table2array(T2(:,3));
T3 = readtable('3.3ghs_datafiles.csv','NumHeaderLines',3);%i have to eliminate 1 rows which is having header names a,b, r
d = table2array(T3(:,3));
T4 = readtable('3.4ghs_datafiles.csv','NumHeaderLines',3);%i have to eliminate 1 rows which is having header names a,b, r
e = table2array(T4(:,3)); % <<< don't overwrite d
% xaxis=120:0.1:120.5;
whos
% Final_T=cat(a,b,c,d);%i have to collect 3rd column data from all the files and store in 1 variable
xaxis = linspace(120, 120.5, numel(a)); % xaxis with the same number of elements as your other variables
e = e(1:22,:); % trim off the extra row from e
Final_T = [a b c d/1e64 e/1000]; % scale d and e so you can see that a, b, and c aren't all zeros
plot(xaxis, Final_T)
legend({'a', 'b', 'c', 'd/1e64', 'e/1000'}, 'Location', 'northwest')
grid on
0 comentarios
Voss
el 16 de Nov. de 2023
Here's one way:
f = [3, 3.1, 3.2, 3.3, 3.4];
Nf = numel(f);
C = cell(1,Nf);
filenames = compose('%gghs_datafiles.csv',f);
for ii = 1:Nf
C{ii} = readtable(filenames{ii});
end
T = vertcat(C{:});
plot(T.b,T.r,'.')
At least one of the files has huge values (~1e64) that prevent you from seeing what the other files' data looks like, so let me plot each file's data in a separate figure:
for ii = 1:Nf
figure
plot(C{ii}.b,C{ii}.r,'.')
title(filenames{ii},'Interpreter','none')
end
0 comentarios
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!