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

 Akzeptierte Antwort

VBBV
VBBV am 12 Feb. 2024
Bearbeitet: VBBV am 13 Feb. 2024

0 Stimmen

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

7 Kommentare

VBBV
VBBV am 12 Feb. 2024
Use struct2cell and then use for loop index, m for cell arrays to plot
Ram Prasanth
Ram Prasanth am 12 Feb. 2024
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
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:
plot(egoStatesRefTrajectory(m).y(:,1),egoStatesRefTrajectory(m).y(:,2))
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 am 13 Feb. 2024
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 am 13 Feb. 2024
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by