How to extract y-value data at a certain x-value?

조회 수: 11 (최근 30일)
aman verma
aman verma 2022년 6월 14일
댓글: Star Strider 2022년 6월 14일
I would like to take all the y values from the attached figure that incercept the x data value of 5x10^5 Hz and then re-create this figure but instead Velocity against Resonator length. Is there a way to do this?
thank you
  댓글 수: 4
KSSV
KSSV 2022년 6월 14일
Yes...it is better to show us the code.
aman verma
aman verma 2022년 6월 14일
편집: Image Analyst 2022년 6월 14일
%% set the elastic constants for the aluminium
E_al=70e9;
mu_al=26e9;
K_al=76e9;
nu_al=0.35;
rho_al=2700;
lambda_al=K_al-2*mu_al/3;
%% set the parameters for the substrate
L=2e-3; % m Lattice spacing
rho=rho_al; % Kg/m^3
mu=mu_al; % Pa shear modulos
lambda=lambda_al; % Pa Lame parameter
E=mu.*(3.*lambda+2.*mu)/(lambda+mu)
E = 7.0016e+10
E=E_al;
Cl=sqrt((lambda+2*mu)./rho);
Ct=sqrt(mu./rho);
nu=lambda./(2.*(lambda+mu));
nu=nu_al;
neta_R=(0.87+1.12.*nu) ./ (1+nu);
CR=Ct*neta_R;
%% set the parameters for the rods / resonators
rho_r=rho_al; % Kg / m^3
mu_r=mu_al; % Pa
lambda_r=lambda_al; % Pa
E_r=E_al;
%h=(L/2-0.5e-3);%0.3e-3; % m resonator diameter
h=0.5e-3;
%l=10e-3; % m resonator length
S=pi.*(h/2)^2; % m^2 resonator area
% shear mode velocity = sqrt(mu/rho);
% longitudanal velocity = sqrt((lambda+2mu)/rho);
r=sqrt(1./(2+mu/lambda));
%% compute bandgaps equation 3.28 - I use this to divide the solution space between the bandgaps
figure;
for x=linspace(0.001,0.01,100)
l=x;
alpha_r=sqrt(rho_r./E_r);
w1=(1./(l.*alpha_r)).*(1*pi-atan(L^2./(S.*sqrt(1-r^2)) .* sqrt(mu.*rho./(E_r.*rho_r))));
w2=(1./(l.*alpha_r)).*(2*pi-atan(L^2./(S.*sqrt(1-r^2)) .* sqrt(mu.*rho./(E_r.*rho_r))));
%% search in 4 segments 0->w1, (w1+w2)/2->w1, (w1+w2)/2->w2, w2 and up.
K0=0.01e3;
KM=5e3;
dK=0.005e3;
w12=(w1+w2)/2;
Kw12=w12/CR;
Kw1=w1/Ct;
Kw2=w2/Ct;
K1=[K0:dK:KM];
%K2=[Kw12:-dK:Kw1];
%K3=[(Kw12+dK):dK:KM];
%K4=[KM:-dK:(Kw2+dK)];
%% now for each segement find the solution using a seed guess and pass on to the next solution
%% BLUE line
i=1; omega_initial=K1(1)*CR;
for k=K1
omega=fminsearch(@(omega) abs(disp_fun(k,omega,rho,lambda,mu,L,rho_r,lambda_r,mu_r,l,S)),omega_initial);
omega_initial=omega; omega1(i)=omega; i=i+1;
end
CP1=omega1./K1; %CP2=omega2./K2; CP3=omega3./K3;
ohm=[min(omega1)];f=ohm./2./pi;
plot([0,max(ohm)]./2/pi,[Ct,Ct],'r:',[0,max(ohm)]./2/pi,[CR,CR],'b:',[w1,w1]./2/pi,[0,Ct*1.1],'k:'); hold on
plot(omega1./2/pi,CP1,'r-')%,omega2./2/pi,CP2,'b-',omega3./2/pi,CP3,'b-');
xlabel('Frequency /Hz'); ylabel('Velocity /ms^-^1'); axis tight
title('Velocity against frequency for changing resonator length')
xlim([0,1000e3])
end
Unrecognized function or variable 'disp_fun'.

Error in solution (line 62)
omega=fminsearch(@(omega) abs(disp_fun(k,omega,rho,lambda,mu,L,rho_r,lambda_r,mu_r,l,S)),omega_initial);

Error in fminsearch (line 201)
fv(:,1) = funfcn(x,varargin{:});

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2022년 6월 14일
The code is incomplete and cannot run as posted.
Using the .fig file instead:
F = openfig('Velocity against frequency for changing resonator length.fig');
Ax = gca(F);
Lm = findobj(Ax, 'Type','line');
Xq = 5E+5;
for k = 1:numel(Lm)
Xv{k,:} = Lm(k).XData;
Yv{k,:} = Lm(k).YData;
Zv{k,:} = Lm(k).ZData;
if numel(unique(Xv{k})) > 1
Yq(k,:) = interp1(Xv{k},Yv{k}, Xq)
else
Yq(k,:) = NaN;
end
end
figure
plot(1:numel(Yq), Yq, 'x')
grid
xlabel('Arbitrary Vector')
ylabel('Velocity')
produces:
Here, ‘Xq’ is the desired frequency of Hz and ‘Yq’ are the interpolated values that intercept that value. Since ‘Resonator Length’ is nowhere defined in the code, I plotted it against the index vectors of ‘Yq’. If ‘ResonatorLength’ is defined, it should be assigned within the if block under both conditions, so that it can be plotted as the independent variable in the figure plotted in my code, for example:
if numel(unique(Xv{k})) > 1
RL(k,:) = "Resonator Length At This Value Of The Existing Data";
Yq(k,:) = interp1(Xv{k},Yv{k}, Xq)
else
RL(k,:) = "Resonator Length At This Value Of The Existing Data";
Yq(k,:) = NaN;
end
and then plot ‘Yq’ against ‘RL’ instead of against ‘Arbitrary Vector’.
.
  댓글 수: 2
aman verma
aman verma 2022년 6월 14일
Thank you so much for your help so far, its really appreciated.
The resonator length is defined by the use of linspace where l is the length of the resonator. How can this linspace be put into RL and thus produce the appropriate plot? (the attached image is an example of what the plot is to look like.
for x=linspace(0.001,0.01,100)
l=x;
Star Strider
Star Strider 2022년 6월 14일
I cannot run the code, so I cannot figure out how ‘x’ is used in it, or with respect to the plot. There does not appear to me to be any specific relation between ‘x’ (or ‘l’) and whatever is being plotted.
So, I am going with this option:
RL = linspace(0.001,0.01,numel(Yq));
figure
plot(RL, Yq, 'x')
grid
xlabel('Resonator Length')
ylabel('Velocity')
producing this plot:
That is the best I can do.
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by