Plotting X,Y,Z Data
30 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Guilherme
2023 年 3 月 17 日
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
採用された回答
Star Strider
2023 年 3 月 17 日
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')
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!