How do I extract data from MATLAB figures? (some error)

I want to extract 'y data' value from a fig file.
I input the following code in Matlab R2018b:
ezplot('y*(0.6326*log(y)+4.419*y + 30.48) - 80*sin(x)^2',[-5 5 -1 4])
>> h= gcf;
axObjs = h.Children
dataObjs = axObjs.Children
x = dataObjs(1).XData
y = dataObjs(1).YData
but I get the value for 'x axis' and 'y axis'. I don't need y axis. I only want to get the value of y date.
No matter what i do i can't make this to work. It's very strange. Any help will be greatly appreciated. Thanks in advance.

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 7일
편집: Ameer Hamza 2020년 10월 7일
ezplot() is being depreciated. Also, it generates a contour object, which is not so helpful to extract the data. Use fimplicit instead.
f = fimplicit(@(x, y) y.*(0.6326*log(y)+4.419*y + 30.48) - 80*sin(x).^2, [-5 5 -1 4]);
h= gcf;
axObjs = h.Children;
dataObjs = axObjs.Children;
x = dataObjs(1).XData;
y = dataObjs(1).YData;

댓글 수: 4

why didn't use dot log(y) and 4.419y but did sin(x). ??
I would appreciate it if you could explain why.
But x is a vector, and therefore, sin(x) is a vector. But I don't want to do matrix multiplication. I want to do element-wise square; therefore, I specified .^ to let MATLAB know element-wise multiplication. For terms
0.6326*log(y)
4.419*y
It is a scalar multiplying with vector. You can use both * or .* There is no difference. I just skipped them for convenience.
It was really helpful!! Thanks for your help.
I am glad to be of help!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

2020년 10월 7일

댓글:

2020년 10월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by