how to import file?
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Les Beckham
2023년 11월 16일
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
Voss
2023년 11월 16일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!