필터 지우기
필터 지우기

how to get data from an interval

조회 수: 6 (최근 30일)
federico midei
federico midei 2020년 9월 26일
댓글: Ameer Hamza 2020년 9월 27일
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