How do I plot data from a structure with time?

조회 수: 109 (최근 30일)
Kieran Reeves
Kieran Reeves 2016년 2월 4일
댓글: LUIS ANGEL OLVERA OLVERA 2018년 11월 20일
I have a structure with time from my scope in Simulink sent back to Matlab. I am unsure of what script code to use in Matlab to plot the data against time as I see it in the scopes in Simulink.
The structure is called Control_Logic
The signals area as follows.
How do I plot each individual signal vs time? Thanks Kieran
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 2월 4일
Could you show us
fieldnames(Control_Logic.signals)
and also if you could drag the divider between "values" and "dimensions" further right on the information, then you should be able to see the full information about the size of the first field; we can see it is 108350 by something but we cannot see what at the moment.
Kieran Reeves
Kieran Reeves 2016년 2월 4일
Hi Walter
>> fieldnames(Control_Logic.signals)
ans =
'values'
'dimensions'
'label'
'title'
'plotStyle'
Which appear to just be the column titles
Kieran

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2016년 2월 4일
편집: Guillaume 2016년 2월 4일
Most likely, this will work:
plot(Control_Logic.time, [Control_Logic.signals.values])
The [Control_Logic.signals.values] concatenates the values field of the 3 signal structures together into a 108350 x 3 matrix (assuming that values is 108350 x 1).
  댓글 수: 3
Guillaume
Guillaume 2016년 2월 4일
subplot(2, 2, 1); plot(Control_Logic.time, Control_Logic.signals(1).values);
subplot(2, 2, 2); plot(Control_Logic.time, Control_Logic.signals(2).values);
subplot(2, 2, 3); plot(Control_Logic.time, Control_Logic.signals(3).values);
is one way to do it.
Kieran Reeves
Kieran Reeves 2016년 2월 4일
Thank you so much.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Lars Lindner
Lars Lindner 2018년 11월 9일
Hi everybody, I have the exact same problem. Trying the command
plot(data.time, data.signals(1).values)
gives me the error shown in following image:
Does anybody has an idea, what I am doing wrong?
Thanks everybody and with nice greetings, Lars
  댓글 수: 1
LUIS ANGEL OLVERA OLVERA
LUIS ANGEL OLVERA OLVERA 2018년 11월 20일
Hi,
You have an issue using singleton dimensions, please review "squeeze"
squeeze Remove singleton dimensions.
B = squeeze(A) returns an array B with the same elements as
A but with all the singleton dimensions removed. A singleton
is a dimension such that size(A,dim)==1. 2-D arrays are
unaffected by squeeze so that row vectors remain rows.
NewArray=squeeze(data.signals(1).values)
This function will turn your initially (1,1,10161) structure to a new (10161,1) array which can be used with your time array
To graph:
plot(data.time, A)
I hope this is useful for your project!
Luis Olvera

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Scopes and Data Logging에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by