How can I read CSV file and plot without removing header?

85 Ansichten (letzte 30 Tage)
Md. Imtiaz Kamrul
Md. Imtiaz Kamrul am 30 Jun. 2022
Kommentiert: Voss am 30 Jun. 2022
I want to read CSV file without removing header. The first row is the header. I tried with readtable but then I can not able to read the column as well. It is showing Invalid subscript error. I've attached the csv file and code in here.
A= dlmread('v1.csv'); %data read
freq= A(:,1); % it contains the frequency column
S11= A(:,2); % it contains S11 which is 2nd column
S21= A(:,3); % it contains S21 which is 3rd column
figure;
plot(freq,S11,'-','LineWidth',1.5,'color',[30,129,176]/255);
hold on;
plot(freq,S21,'-','LineWidth',1.5,'color',[215,74,31]/255);

Akzeptierte Antwort

Voss
Voss am 30 Jun. 2022
A = readtable('v1.csv')
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
A = 6691×3 table
Freq_GHz_ dB_S_P1_P1____ dB_S_P2_P1____ _________ ______________ ______________ 0.1 -26.042 -0.075703 0.11 -25.243 -0.081879 0.12 -24.517 -0.088211 0.13 -23.851 -0.09466 0.14 -23.237 -0.10119 0.15 -22.668 -0.10779 0.16 -22.138 -0.11444 0.17 -21.641 -0.12113 0.18 -21.174 -0.12785 0.19 -20.735 -0.13461 0.2 -20.319 -0.1414 0.21 -19.925 -0.14824 0.22 -19.551 -0.15511 0.23 -19.194 -0.16204 0.24 -18.855 -0.16901 0.25 -18.53 -0.17604
figure;
plot(A{:,1},A{:,2},'-','LineWidth',1.5,'color',[30,129,176]/255);
hold on;
plot(A{:,1},A{:,3},'-','LineWidth',1.5,'color',[215,74,31]/255);

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by