Help importing and reading .csv file and graphing

8 ビュー (過去 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?
  1 件のコメント
Zachary
Zachary 2024 年 10 月 8 日
Also, there are over 600,000 data points.

サインインしてコメントする。

回答 (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 Center および File Exchange2-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