PLOT CSV FILE IN MATLAB

조회 수: 64 (최근 30일)
Willian Alexander Correa Reyes
Willian Alexander Correa Reyes 2021년 7월 8일
댓글: Ankit 2021년 7월 9일
Good Morning,
I am trying to graph the attached .csv file but it does not run correctly, my code is as follows.
t,p = csvread('re.csv',1,0);
y_line_1= tmp(:,7);
x_line_1= tmp(:,3);
plot(x_line_1,y_line_1,'b-')
I appreciate the help.
Willian
X axis: P2
Y axis: P6

채택된 답변

Ankit
Ankit 2021년 7월 8일
편집: Ankit 2021년 7월 8일
csvread: The file can only contain numeric values.
I would prefer readtable command. With this command you have flexibility to use variety of import options too. This "opts" object contains properties that control the data import process.
For more info on readtable see the following link - readtable
tmp = readtable('re.csv');
y_line_1= table2array(tmp(:,7));
x_line_1= table2array(tmp(:,3));
plot(x_line_1,y_line_1,'b-')
  댓글 수: 3
Jeremy Hughes
Jeremy Hughes 2021년 7월 8일
I see this a lot:
table2array(tmp(:,7)) % extracts a sub table then converts it to an array
Which is a complicated way of doing:
tmp.(7) % directly extracts the seventh variable.
Also, in newer releases you could be using:
tmp = readmatrix('re.csv');
Ankit
Ankit 2021년 7월 9일
@Jeremy Hughes thanks for the suggestion :) I am looking forward for readmatrix command

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by