CSV huge data and mesh grid.

27 visualizaciones (últimos 30 días)
Dimitris Lassithiotakis
Dimitris Lassithiotakis el 15 de Ag. de 2021
Comentada: Star Strider el 31 de Ag. de 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

Respuesta aceptada

Star Strider
Star Strider el 15 de Ag. de 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))
T1 = 4888×5 table
Time X Y Z Vector ________ ___ ___ ____ ______ 0.029046 -72 99 -167 207.06 0.031694 -4 17 -163 163.93 0.034342 12 -27 -197 199.2 0.036989 32 51 -159 170.02 0.039637 57 39 -188 200.28 0.042284 17 -11 -240 240.85 0.044933 21 24 -192 194.63 0.04758 48 44 -167 179.25 0.05008 55 91 -120 160.33 0.052728 103 76 -120 175.46 0.055375 92 60 -183 213.43 0.058023 55 105 -140 183.44 0.060671 33 5 -192 194.88 0.063319 -4 -24 -277 278.07 0.065966 85 83 -168 205.76 0.068584 132 32 -197 239.28
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 comentarios
Dimitris Lassithiotakis
Dimitris Lassithiotakis el 31 de Ag. de 2021
Hi again and many thanks for that. Seems that the data are scattered all over the place indeed, but valuable information can be withdrawn once we have many more to play with, or play in a lab environment with known frequencies to correlate these data.
I managed to write the software to read all the Excel files from a directory, count them, discard some of them based on size criteria and display certain information as well as getting 5 figures and graphs on the screen.
The problem I am facing is that although the calculations have finished, surfing the figures takes some time due to the huge amount of data. My question is: Is there any way to measure that and tell the user to wait? I use the drawnow function, but still I'd like to tell the user that Matlab is doing something in the background.
Once again your help is much appreciated,
D.
Star Strider
Star Strider el 31 de Ag. de 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.
.

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by