Plotting multiple input CSV on 3D graph

6 views (last 30 days)
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!

Accepted Answer

KSSV
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
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)
Robin L
Robin L on 3 Feb 2021
Thanks! It had trouble with putting the data of the table into the double variables, so my way to fix it was to use readmatrix instead of readtable, seems to be working now.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!