Plotting multiple input CSV on 3D graph
6 views (last 30 days)
Show older comments
Hello,
I have made a succesfull 2D plot of a single CSV file.
Now I was wondering if I could use the same code to plot multiple of these files to create a 3D plot.
Is there a simple way of just telling matlab to import all CSV files found in the directory, and use them chronologically where first drill is dataset #1, 2nd #2, etc?
Each CSV contains datapoints of multiple voltages/currents/accelerations measured from a CNC machine.
So it would show the Voltage, Current, Power, etc on the z-axis, time on the x-axis and # of drill on the y-axis.
Thanks!
0 Comments
Accepted Answer
KSSV
on 29 Jan 2021
You need to proceed something like below:
csvFiles = dir('*.csv') ; % get all csv files
N = length(csvFiles) ;
m = 100 ; % this is the row numbers in each csv file
Voltage = zeros(m,N) ;
Current = zeros(m,N) ;
Power = zeros(m,N) ;
for i = 1:N
data = csvread(csvFiles(i).name) ;
Voltage = data(:,1) ; % assuming first column is voltage
Current = data(:,2) ;
Power = data(:,3) ;
end
surf(Voltage, Current, Power)
3 Comments
KSSV
on 1 Feb 2021
You are not saving the data into the initalized matrices.
%clear everything
clc
close all
clear all
%compare files in 1 graph
%declare folder containing the files
d = uigetdir(pwd, 'Select a folder');
csvFiles = dir(fullfile(d, '*.csv')); % get all csv files
L = length(csvFiles); %amount of csv files
m = 250000; % this is the row numbers in each csv file
%create variables
UH_V = zeros(m,L);
IH_A = zeros(m,L);
IV_A = zeros(m,L);
A_G = zeros(m,L);
%read data from files
for i = 1:L
data = readtable(csvFiles(i).name); %read table of every file
%delete first column and first 3 rows
data(:,[1]) = [];
data([1,2,3],:) = [];
UH_V(:,i) = data(:,1); % assuming first column is voltage
IH_A(:,i) = data(:,2);
IV_A(:,i) = data(:,3);
A_G(:,i) = data(:,4);
end
% surf(UH_V, IH_A, IV_A)
More Answers (0)
See Also
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!