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

조회 수: 5 (최근 30일)
Md. Imtiaz Kamrul
Md. Imtiaz Kamrul 2022년 6월 30일
댓글: Voss 2022년 6월 30일
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);

채택된 답변

Voss
Voss 2022년 6월 30일
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);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by