How to make comparison plot in a struct

I have a time series data of Y-position of the vehicle trajectory inside a struct of 1*41 struct.
I want to compare each time step of all the 41 timeseries across.
This is the code i created but its not working. can you help me with these?
Code is:
figure;
for m = 1:41
hold on;
plot(egoStatesRefTrajectory.y(:,1),egoStatesRefTrajectory.y(:,2))
end

 採用された回答

VBBV
VBBV 2024 年 2 月 12 日
編集済み: VBBV 2024 年 2 月 13 日

0 投票

plot(egoStatesRefTrajectory(m).y(:,1),egoStatesRefTrajectory(m).y(:,2))

7 件のコメント

VBBV
VBBV 2024 年 2 月 12 日
Use struct2cell and then use for loop index, m for cell arrays to plot
Ram Prasanth
Ram Prasanth 2024 年 2 月 12 日
Hi @VBBV Thank you for your answer.
I tried it but i am getting dot indexing error.
For example inside time series i have 2 coulumns of data as shown below.
Inside each time series i have data's like this
Ram Prasanth
Ram Prasanth 2024 年 2 月 12 日
Yes i did that too but it was same.
This is how i changed my code:
egoStatesRefTrajectory1=struct2cell(egoStatesRefTrajectory);
%%
figure;
for m = 1:41
hold on
plot(egoStatesRefTrajectory1.y{m}(:,1),egoStatesRefTrajectory1.y{m}(:,2))
end
the error message i got is:
VBBV
VBBV 2024 年 2 月 12 日
plot(egoStatesRefTrajectory(m).y(:,1),egoStatesRefTrajectory(m).y(:,2))
Ram Prasanth
Ram Prasanth 2024 年 2 月 12 日
Hello @VBBV,
I tried this too but still it dosent work.
So i changed the code as below and now it is working:
sample_states_forplots = simout.logsout.get('B_x_egostates').Values;
%%
% egoStatesRefTrajectory1=struct2cell(egoStatesRefTrajectory);
%%
% for m = 1:41
% hold on;
% plot(egoStatesRefTrajectory(m).y(:,1),egoStatesRefTrajectory(m).y(:,2))
% end
%%
% Number of points in the timeseries
NbPointsTimeSeries = length(sample_states_forplots.egoStatesRefTrajectory(m).y.Time);
Y_traj = zeros(NbPointsTimeSeries, 41);
for m = 1:41
hold on
%plot(egoStatesRefTrajectory1.y{m}(:,1),egoStatesRefTrajectory1.y{m}(:,2))
Y_traj(:,m) = sample_states_forplots.egoStatesRefTrajectory(m).y.Data;
end
vTimeTimeseries = sample_states_forplots.egoStatesRefTrajectory(m).y.Time;
vTime = 0:0.1:4;
figure; hold on; grid on;
for idx = 500:100:1500
plot(vTime + vTimeTimeseries(idx),Y_traj(idx,:))
end
I hope there might be a simple solution for this but i am not sure of it.
VBBV
VBBV 2024 年 2 月 13 日
Ok, It seems like data is nested in different structures from which you extract. The problem in your question however is shown in highly simplified form for anyone to comprehend.
Ram Prasanth
Ram Prasanth 2024 年 2 月 13 日
ok thank you very much for your feedback. Next time i will post it in a much detailed manner for better comprehension or understanding of the problem. Thank you @VBBV

サインインしてコメントする。

その他の回答 (0 件)

製品

リリース

R2022b

質問済み:

2024 年 2 月 12 日

コメント済み:

2024 年 2 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by