Help importing and reading .csv file and graphing

71 次查看(过去 30 天)
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 个)

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.

请先登录,再进行评论。


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')

请先登录,再进行评论。

标签

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by