how to get data from an interval

6 次查看(过去 30 天)
Hi, I need to use the y values between the x=50 and x=180 values to do another plot. How can I get these vaules from the current plot? I've readed some answers using the 'findobj' function but I don't know if it's the correct function for my task and I don't understand how to use it in my specific situation.
Could someone help me please?
here's my code:
clc;
clear;
close all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
P=0.5*800000;%kN -carico agente
R=20;%mm -raggio medio
L=3*75;%mm -lunghezza tubo
s=1;%mm -spessore di parete
ni=0.3;% -coeff poisson
E=210000;%MPa -modulo young
w=2;%MPa -pressione int/ext
K=0.5;% -incasto incastro
%equazioni derivanti dall'equilibrio radiale:
E1=E/(1-(ni^2));% -modulo young dilataz laterale impedita
I=(2*pi*R*(s^3))/12;% -momento di inerzia cilindro
k=2*pi*((E*s)/R);% -rigidezza molla fondazione
Pcr=sqrt(4*k*E1*I)% -carico critico
Pcre=((pi)^2*E*I)/(K*((L/1000)^2))% -carico critico secondo Eulero
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f = @(z,u) [u(2); u(3); u(4); (-1/(E1*I))*((P*u(3))+(k*u(1)))]; %equazione differenziale w=0
bc = @(ua, ub) [ua(1); ua(2)-0.00000001; ub(1); ub(2)+0.00000001];
zmesh = linspace(0, L, 100000);%crea vettore equispaziato da 0->lunghezza cilindro
iguess= @(z) [0; 0; 0; 0];%initial guess @soluzione dalla quale inizia l'iterazione della function bvp4c
solinit = bvpinit(zmesh, iguess); %reference @doc bvpinit (form initial guess value)
opts = bvpset('RelTol',0.1,'AbsTol',0.1,'Stats','on'); %setting per ottenere le statistiche della function bvp4c
sol= bvp4c(f, bc, solinit,opts)% sol in x, y values
figure
hold on
grid on
plot(sol.x(1,:),sol.y(1,:),'.') %I need the y values from this plot for x from 50 to 180
legend('w=0');
xlabel('z');
ylabel('solution u');

采纳的回答

Ameer Hamza
Ameer Hamza 2020-9-26
编辑:Ameer Hamza 2020-9-26
You can use logical indexing. Add these lines at the end of your code
x = sol.x;
y = sol.y;
idx = (x > 50) & (x < 180);
figure
hold on
grid on
plot(x(idx), y(1, idx))
  6 个评论
federico midei
federico midei 2020-9-27
running this I get this error :
Unable to resolve the name sol.x.
Error in Untitled (line 36)
% x = sol.x;
Ameer Hamza
Ameer Hamza 2020-9-27
Please check the code in the updated comment. You were using Sol as a variable name. I mistakenly typed sol.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by