how to get data from an interval

4 visualizzazioni (ultimi 30 giorni)
federico midei
federico midei il 26 Set 2020
Commentato: Ameer Hamza il 27 Set 2020
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');

Risposta accettata

Ameer Hamza
Ameer Hamza il 26 Set 2020
Modificato: Ameer Hamza il 26 Set 2020
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 Commenti
federico midei
federico midei il 27 Set 2020
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 il 27 Set 2020
Please check the code in the updated comment. You were using Sol as a variable name. I mistakenly typed sol.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by