Help importing and reading .csv file and graphing

6 vues (au cours des 30 derniers jours)
Zachary
Zachary le 8 Oct 2024
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 commentaire
Zachary
Zachary le 8 Oct 2024
Also, there are over 600,000 data points.

Connectez-vous pour commenter.

Réponses (2)

KSSV
KSSV le 8 Oct 2024
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 commentaire
Walter Roberson
Walter Roberson le 8 Oct 2024
T = readtable('myFile.csv') ;
figure
plot(T.(1),T.(2),'r')
hold on
plot(T.(1),T.(3),'b')
hold off
legend('data1','data2')

Connectez-vous pour commenter.


Zinea
Zinea le 8 Oct 2024
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 commentaire
Walter Roberson
Walter Roberson le 8 Oct 2024
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by