I plot a figure by using a function from a package.
Now I'd like to know the x and y values once I plot the curve.
Where are they stored

 채택된 답변

Star Strider
Star Strider 2020년 1월 14일

1 개 추천

Try this:
F = openfig('untitled.fig');
ax = gca;
lines = findobj(ax, 'Type','Line');
for k = 1:numel(lines)
x{k,:} = lines(k).XData;
y{k,:} = lines(k).YData;
end
The x- and y-data for each line are in their appropriate cell arrays.

댓글 수: 4

Paul Rogers
Paul Rogers 2020년 1월 14일
that works great,
One last thing fi you could.
I need to plot but with a diffferent x
x = -0.2:0.01:0.8;
Can you just write me a piece of code for that, please?
Something like this
for k = 1:numel(lines)
y{k,:} = lines(k).YData;
plot(FlowVector,y{k,:})
hold on
end
the x is always the same
Star Strider
Star Strider 2020년 1월 14일
I am not certain what you intend withh ‘...plot but with a different x
Two possibilities:
F = openfig('Puntitled.fig');
ax = gca;
lines = findobj(ax, 'Type','Line');
for k = 1:numel(lines)
x{k,:} = lines(k).XData;
y{k,:} = lines(k).YData;
end
newx = -0.2:0.01:0.8;
for k = 1:numel(lines)
newy{k,:} = interp1(x{k}, y{k}, newx, 'linear','extrap'); % Interpolate-Extrapolate
end
or:
figure
plot(newx, cell2mat(newy)) % Plot Interpolated Values
grid
figure
plot(cell2mat(x).', cell2mat(y).') % Plot Previous Data With New X-Axis Ticks
xt = get(gca, 'XTick');
set(gca, 'Xtick',xt, 'XTickLabel',newx)
grid
One of these should do what you want.
Paul Rogers
Paul Rogers 2020년 1월 14일
for k = 1:numel(lines)
figure(4)
plot(FlowVector,y{k,:})
grid on
hold on
end
here's is the solution.
Man, thank you a lot, you really helped me.
I couldn't figured out without your help.
Star Strider
Star Strider 2020년 1월 14일
As always, my pleasure!
That’s what I’m here for!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

제품

릴리스

R2014b

태그

질문:

2020년 1월 14일

댓글:

2020년 1월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by