cannot extract data from figure with multiple lines

조회 수: 5 (최근 30일)
Nathaniel Goldfarb
Nathaniel Goldfarb 2022년 4월 5일
댓글: Fangjun Jiang 2022년 4월 6일
Hello,
I have a matlab figure with muliple lines in it that I am trying to extact. However I can only get the figure line. I am not sure what is wrong. I created the figures in simulink
I am using the following code
fig = openfig('traj.fig');
h = findobj(gca,'Type','line');
y_no_humanX = get(h,'Xdata') ;
y_no_humanY = get(h,'Ydata') ;
close(fig);
when I try to extract the data I only get the first line and cannot get the other lines. I am not sure what is going on.
Any ideas?

채택된 답변

Fangjun Jiang
Fangjun Jiang 2022년 4월 5일
편집: Fangjun Jiang 2022년 4월 5일
The other two "curves" are created using stairs(). use findobj(fig,'Type','Stair') to find those.
fig = openfig('traj.fig');
>> findobj(fig)
ans =
12×1 graphics array:
Figure (ScopePrintToFigure)
UIContainer (PrintLayoutGridContainer)
UIContainer (PrintContainer)
Panel (DisplayPanel1)
Legend (ref, Subsystem/1, Subsystem/3)
Axes (DisplayAxes1_RealMag)
Stair (DisplayLine2)
Stair (DisplayLine1)
Line (DisplayLine1)
Transform
Transform
Transform
  댓글 수: 4
Nathaniel Goldfarb
Nathaniel Goldfarb 2022년 4월 5일
Thankyou, this helped a lot. I was able to change the line type from "stair" to "line" and resave the figure.
I was then able to read in the data using my other code. I am sure there is a better way but I only need to do this for two figures so its not that big a deal.
Fangjun Jiang
Fangjun Jiang 2022년 4월 6일
If you have access to the Simulink model and simulation, you could save those data directly using the "To Workspace" block.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by