Plotting X,Y,Z Data

31 visualizzazioni (ultimi 30 giorni)
Abdullah Azzam
Abdullah Azzam il 17 Mar 2023
Commentato: Star Strider il 18 Mar 2023
Hi All,
I have a data set that shows changes of strain at differnt locations in time domain where my X and Y axis are the location and the strain value and the Z axis is the time domain. However, when using plot3 the graphs look distorted as shown in attached image. I have uploaded the data set also in here in case someone can help me with it. When looking at the uploaded csv file, column A is time, B is location (Angle), and the rest of the column are different data parameter, in the image shown I have been using column G value that contain the strains. What would be the best way to plot those data at differnt timesteps (i.e. every 100 time setp.). Below is the code I have used to plot given that Matrix is just the matrix that contain the csv file data. I have been using for loop to get the data every 500 timesetp as which is shown in the attached csv file. I have also tried removing the zeros at the end of the matrix but the results are the same.
Thanks for the help in advance
plot3(Matrix(:,1),Matrix(:,2),Matrix(:,7))
  1 Commento
Guilherme
Guilherme il 17 Mar 2023
Can you please share an snippet on how you're defining your matrix? It seems that doing plot3(Matrix...) is getting all the values independent of the time stamp. You should probably create a structure where you do multiple plots, everyone of them for a single time stamp, for instance:
count = 0;
sample_jump = 500;
for i = 1:n_time_samples
plot3(Matrix(count+1:1:sample_jump,1),Matrix(count+1:1:sample_jump,2),Matrix(count+1:1:sample_jump,7));
count = count+sample_jump;
end

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 17 Mar 2023
With a bit of help from accumarray, it is possible to separate the traces so that there are no connecting lines —
Matrix = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1328180/Strain%20Data.csv')
Matrix = 119934×9
1.0000 0 22.0000 0 0 -0.0000 -0.0000 0 0 1.0000 6.0000 21.8800 2.2996 0 -0.0000 -0.0000 0 0 1.0000 12.0000 21.5190 4.5741 0 -0.0000 -0.0000 0 0 1.0000 18.0000 20.9230 6.7984 0 -0.0000 -0.0000 0 0 1.0000 24.0000 20.0980 8.9482 0 -0.0000 -0.0000 0 0 1.0000 30.0000 19.0530 11.0000 0 -0.0000 -0.0000 0 0 1.0000 36.0000 17.7980 12.9310 0 -0.0000 -0.0000 0 0 1.0000 42.0000 16.3490 14.7210 0 -0.0000 -0.0000 0 0 1.0000 48.0000 14.7210 16.3490 0 -0.0000 -0.0000 0 0 1.0000 54.0000 12.9310 17.7980 0 -0.0000 -0.0000 0 0
M127 = sortrows(Matrix(:,[1 2 7]),1);
[U1,ix1,ix2] = unique(M127(:,1),'stable'); % Column #1 Unique Values & Indices
Uix2 = unique(ix2);
for k = 1:size(M127,2)
Col{k,:} = accumarray(ix2, M127(:,k), [], @(x){x}); % Separate Rows By 'ix2'
end
% Col
% minLen = min(cellfun(@numel,Col{1}))
for k = 1:4
Set{k,:} = [Col{1}{k+1} Col{2}{k+1} Col{3}{k+1}]; % Creeate Data Sets
end
% Len = 2:minLen;
figure
hold on
for k = 1:numel(Set)
plot3(Set{k}(2:end,1), Set{k}(2:end,2), Set{k}(2:end,3), 'LineWidth',1.5, 'DisplayName',"Set "+k)
end
hold off
grid on
xlabel('X')
ylabel('Y')
zlabel('Z')
legend('Location','best')
view(30,30)
There was a duplicated ‘x’ value in ‘Set 3’ that was causing a straight line to appear where no lines should appear. That was solved by beginning the indexing with 2 in the plot3 calls.
.
  2 Commenti
Abdullah Azzam
Abdullah Azzam il 18 Mar 2023
@Star Strider This has worked thanks for the help. Good to know that you need to break up your big matrix into smaller ones before plotting in matlab. Thanks for the help
Star Strider
Star Strider il 18 Mar 2023
As always, my pleasure!

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by