Getting error while trying to access the data of the following plot.

1 次查看(过去 30 天)
syms x
warning off
alpha = -0.1;
sigma = 0.1;
eps = -0.1;
e = 0.2;
a = 2;
lambda = 2;
M = 4;
psi_list = [10, 30, 40, 50, 5, 15, 20, 25];
figure
hold on
for i = 1:numel(psi_list)
psi = psi_list(i);
hbar = @(x) a - a.*x + x;
A1 = eps + alpha^3 + (3 * sigma^2 * alpha);
B1 = @(x) (-3 * lambda * M) * ((hbar(x).^2) + (2 .* hbar(x) .* alpha) + (sigma^2) + (alpha^2));
a1 = @(x) tanh(M .* hbar(x));
b1 = @(x) 1 - ((tanh(M .* hbar(x))).^2);
c1 = (M * alpha) - ((M^3 * A1)/3);
d1 = 2 * (M^2) * (1 + lambda);
C1 = @(x) a1(x) + (b1(x) .* c1);
D1 = @(x) d1 .* ((hbar(x).^3) + (3 .* (hbar(x).^2) .* alpha) + (3 .* hbar(x) .* (alpha)^2) + (3 .* hbar(x) .* (sigma)^2) + eps + (3 * alpha * (sigma^2)) + (alpha^3));
f1 = @(x) B1(x) + (3 * lambda .* C1(x) .* hbar(x)) + (3 * lambda .* C1(x) .* alpha) + (D1(x) .* C1(x));
f2 = @(x) 12 * (M^2) * (1 + lambda) .* C1(x);
f3 = psi * (e^3);
f4 = (1 + lambda) *180 * ((1 - e)^2); % 180 is not given in paper
f5 = 1/(2 + lambda);
F = @(x) ((f5 .* f1(x))./f2(x)) + (f3/f4);
q1 = @(x) hbar(x) ./ (2 .* F(x));
Q1 = integral(q1,0,1);
q2 = @(x) 1./(F(x));
Q2 = integral(q2,0,1);
Q = Q1/Q2;
p1 = @(x) (1./F(x)) .* ((0.5 .* hbar(x)) - Q);
P = @(x) integral(p1,0,x);
fplot(P, [0 1])
end
legend(num2str(psi_list'))
ylim([0 1])
set(gca, 'ytick', 0:0.1:1);
set(gca, 'xtick', 0:0.2:1);
xlabel('x')
ylabel('P(x)')
I have tried to access its data but getting error as .....
Index exceeds the number of array elements. Index must not exceed 0.
using the code
open('example.fig');
h = findobj(gca,'Type','line')
x1=get(h(1),'Xdata') ;
y1=get(h(1),'Ydata') ;
x2=get(h(2),'Xdata') ;
y2=get(h(2),'Ydata') ;
x3=get(h(3),'Xdata') ;
y3=get(h(3),'Ydata') ;
x4=get(h(4),'Xdata') ;
y4=get(h(4),'Ydata') ;
x5=get(h(5),'Xdata') ;
y5=get(h(5),'Ydata') ;
x6=get(h(6),'Xdata') ;
y6=get(h(6),'Ydata') ;
x7=get(h(7),'Xdata') ;
y7=get(h(7),'Ydata') ;
x8=get(h(8),'Xdata') ;
y8=get(h(8),'Ydata') ;

采纳的回答

KSSV
KSSV 2022-7-14
You are plotting the data using fplot. This will give you the function, which you have used to plot when you try to extract the data from figure. If you insist to extract the data from figure (which is not necessary) you may consider using plot.
syms x
warning off
alpha = -0.1;
sigma = 0.1;
eps = -0.1;
e = 0.2;
a = 2;
lambda = 2;
M = 4;
psi_list = [10, 30, 40, 50, 5, 15, 20, 25];
figure
hold on
for i = 1:numel(psi_list)
psi = psi_list(i);
hbar = @(x) a - a.*x + x;
A1 = eps + alpha^3 + (3 * sigma^2 * alpha);
B1 = @(x) (-3 * lambda * M) * ((hbar(x).^2) + (2 .* hbar(x) .* alpha) + (sigma^2) + (alpha^2));
a1 = @(x) tanh(M .* hbar(x));
b1 = @(x) 1 - ((tanh(M .* hbar(x))).^2);
c1 = (M * alpha) - ((M^3 * A1)/3);
d1 = 2 * (M^2) * (1 + lambda);
C1 = @(x) a1(x) + (b1(x) .* c1);
D1 = @(x) d1 .* ((hbar(x).^3) + (3 .* (hbar(x).^2) .* alpha) + (3 .* hbar(x) .* (alpha)^2) + (3 .* hbar(x) .* (sigma)^2) + eps + (3 * alpha * (sigma^2)) + (alpha^3));
f1 = @(x) B1(x) + (3 * lambda .* C1(x) .* hbar(x)) + (3 * lambda .* C1(x) .* alpha) + (D1(x) .* C1(x));
f2 = @(x) 12 * (M^2) * (1 + lambda) .* C1(x);
f3 = psi * (e^3);
f4 = (1 + lambda) *180 * ((1 - e)^2); % 180 is not given in paper
f5 = 1/(2 + lambda);
F = @(x) ((f5 .* f1(x))./f2(x)) + (f3/f4);
q1 = @(x) hbar(x) ./ (2 .* F(x));
Q1 = integral(q1,0,1);
q2 = @(x) 1./(F(x));
Q2 = integral(q2,0,1);
Q = Q1/Q2;
p1 = @(x) (1./F(x)) .* ((0.5 .* hbar(x)) - Q);
P = @(x) integral(p1,0,x);
xi = linspace(0,1) ;
PP = zeros(size(xi)) ;
for j = 1:length(xi)
PP(j) = P(xi(j)) ;
end
plot(xi,PP)
end
legend(num2str(psi_list'))
ylim([0 1])
set(gca, 'ytick', 0:0.1:1);
set(gca, 'xtick', 0:0.2:1);
xlabel('x')
ylabel('P(x)')
  5 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by