Plotting multiple input CSV on 3D graph

조회 수: 6 (최근 30일)
Robin L
Robin L 2021년 1월 29일
댓글: Robin L 2021년 2월 3일
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