Help importing and reading .csv file and graphing

조회 수: 15 (최근 30일)
Zachary
Zachary 2024년 10월 8일
댓글: Walter Roberson 2024년 10월 8일
I have a .csv file with three columns: time, Data #1, and Data #2. How do I import that data, have matlab read it, and then generate two graphs: one as time vs. Data #1, and time vs. Data #2. What do I do?

답변 (2개)

KSSV
KSSV 2024년 10월 8일
T = readtable('myFile.csv') ;
figure
hold on
plot(t,T.(1),'r')
plot(t,T.(2),'b')
legend('data1','data2')
Where t is your defined time stampe vector, whose size is equalt to data1 and data2.
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 10월 8일
T = readtable('myFile.csv') ;
figure
plot(T.(1),T.(2),'r')
hold on
plot(T.(1),T.(3),'b')
hold off
legend('data1','data2')

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


Zinea
Zinea 2024년 10월 8일
Hi Zachary,
I see that you want to read a .CSV file with over 600,000 data points having 3 columns.
For achieving this, the data needs to be imported into MATLAB using the readtable’ function, followed by extracting the columns and finally plotting the data. You can refer to the below reference code:
% Read the CSV file into a table
data = readtable('path_to_csv_file');
% Extract columns into variables
time = data.time;
data1 = data.Data_1; % Adjust based on actual column name
data2 = data.Data_2; % Adjust based on actual column name
% Plot time vs Data #1
figure;
plot(time, data1);
title('Time vs Data #1');
xlabel('Time');
ylabel('Data #1');
grid on;
% Plot similarly for Data #2
Below is the output plot for ‘Data #1’ generated using a dummy dataset having 700,000 points:
NOTE: If the .CSV file to be imported is too large and the above method does not suffice, the following links may be helpful:
Hope the above helps you get started, cheers!
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 10월 8일
Depending on the datatypes involved, potentially readmatrix could be used instead of readtable
readtable() would be suitable for the case where the time is expressed as text. readmatrix() would be suitable for the case where the time is expressed numerically.

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

카테고리

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

태그

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by