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
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 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.
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