CSV huge data and mesh grid.
6 views (last 30 days)
Show older comments
Dimitris Lassithiotakis
on 15 Aug 2021
Commented: Star Strider
on 31 Aug 2021
Hi all,
I am quite old to Matlab, but have not used it for so many years (since 2007...) so a lot of rust out there.
I am getting some accelerometer data in a CSV file in the following format:
Time X Y Z Vector
( I combine the X,Y and Z components to find the final vector. )
There are 46 CSV files to read and each one of them creates a unique 2D line using the Time and Vector columns from each CSV file.
Here is the issue...
I want to create a 3D surface, basically by combining these 46 lines. The first 2-3 files do not have the same collumn length, but I can replace that with zeros if need be, or maybe discart them altogether and keep the ones that have the same length.
I have a 360000 x 5 double and I am using the 1st and 5th column. Meshgrid will not do the trick as it's a huge chunk of data.
So far all the data that I have seen to answers do not lead anywhere...
Your help is much appreciated,
I attach one of the files to see an example and here is the code that I have for the time being:
clc;
clear;
format loose;
file='DATA-003.csv';
data=readmatrix(file); %read file
A=data;
A(:,2)=A(:,2)./168.3; %x
A(:,3)=A(:,3)./168.3; %y
A(:,4)=A(:,4)./168.3; %z
for i=1:length(A) %find the vector
A(i,5)=sqrt(A(i,2)^2+A(i,3)^2+A(i,4)^2);
end
x=A(:,1);
y=A(:,5);
figure(1)
% Trick surface into a 2-D plot
surface('XData', [x x], ...
'YData', [y y], ...
'ZData', zeros(numel(x),2), ...
'CData', [y y], ...
'FaceColor', 'none', ...
'EdgeColor', 'interp', ...
'Marker', 'none');
xlim([0 max(x)]);
Kindest regards,
Dimitri
0 Comments
Accepted Answer
Star Strider
on 15 Aug 2021
I am not certain what result you want.
I would do somemthing like this:
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/712632/DATA-003.CSV', 'VariableNamingRule','preserve');
T1.Properties.VariableNames = {'Time','X','Y','Z'};
T1.Vector = sqrt(sum(T1{:,2:4}.^2,2))
One option might be:
VectorMtx = T1.Vector*ones(1,46);
figure
surf(VectorMtx)
xlabel('File Nr')
ylabel('Time [Units]')
zlabel('Column 5 [Units]')
Ideally, you would horizontally concatenate Column 5 from each .csv file to create the matrix, rather than repeating it as I have done here.
To do this in a loop, first find the longest Column 5 vector, then preallocate a (46xN) matrix where ‘N’ is that length, and write each Column 5 vector into it, allowing for differing lengths as:
for k = 1:46
Col5(k) = ...;
VectorMtx(1:numel(Col5(k)),k) = Col5(k);
end
.
8 Comments
Star Strider
on 31 Aug 2021
As always, my pleasure!
I am not certain. The drawnow call could slow the code, so perhaps eliminating that could help. I have no idea how to estimate the time it would take to draw the surf plot. I cannot find any information on that. Perhaps telling the user to please wait for the plots to be drawn or something similar is the only option.
.
More Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!