Plotting multiple input CSV on 3D graph

5 vues (au cours des 30 derniers jours)
Robin L
Robin L le 29 Jan 2021
Commenté : Robin L le 3 Fév 2021
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!

Réponse acceptée

KSSV
KSSV le 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 commentaires
KSSV
KSSV le 1 Fév 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 le 3 Fév 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Import and Analysis dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by