Help importing and reading .csv file and graphing
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
Antworten (2)
KSSV
am 8 Okt. 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 Kommentar
Walter Roberson
am 8 Okt. 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')
Zinea
am 8 Okt. 2024
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:
- https://www.mathworks.com/matlabcentral/answers/231857-loading-large-csv-files
- https://www.mathworks.com/matlabcentral/answers/274076-loading-very-large-csv-files-20gb
Hope the above helps you get started, cheers!
1 Kommentar
Walter Roberson
am 8 Okt. 2024
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.
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!