Plotting multiple input CSV on 3D graph

5 次查看(过去 30 天)
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!

采纳的回答

KSSV
KSSV 2021-1-29
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 个评论
KSSV
KSSV 2021-2-1
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 2021-2-3
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by