200518-如何提取Matlab中figure中的line數據

Ref: How do I extract data points from a plot?
在這裏插入圖片描述

% Create data and plot
x = linspace(-3,3,100)
y1 = sin(x)
y2 = cos(x)

figure(1)

subplot(2,1,1)
plot(x, y1)

subplot(2,1,2)
plot(x, y2)

% Get lines in subplots

h1 = findobj(subplot(2,1,1),'Type','line')
xx1=get(h1,'Xdata')
yy1=get(h1,'Ydata')

h2 = findobj(subplot(2,1,2),'Type','line')
xx2=get(h2,'Xdata')
yy2=get(h2,'Ydata')

% Plot  extracted data
figure(2)

subplot(2,1,1)
plot(xx1, yy1)

subplot(2,1,2)
plot(xx2, yy2)

% Get 'line' data
clc; clear;
lines = findobj(1,'type','line');
Xs = get(lines, 'Xdata');
Ys = get(lines, 'Ydata');

Xs = cell2mat(Xs);
Ys = cell2mat(Ys);

figure(2)
subplot(5,1,5) % the data are inversed from 5 to 1
plot(Xs(1,:),Ys(1,:))

subplot(5,1,4)
plot(Xs(2,:),Ys(2,:))

subplot(5,1,3)
plot(Xs(3,:),Ys(3,:))

subplot(5,1,2)
plot(Xs(4,:),Ys(4,:))

subplot(5,1,1)
plot(Xs(5,:),Ys(5,:))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章