简体   繁体   中英

How to read a table in matlab, find the y values corresponding to x

I want to use the y value corresponding to the given x value from the table (my current table has 1000 values with 10-4 decimal points so I use :

load question_table.mat
eta_p = %assign a value 
F12_p=find( (eta <eta_p+0.01) & (eta > eta_p-0.01), 1, 'first' )

what is missing ?

Here is how I have created the table, run this program.

i = 1;
etaspan = -500:0.001:500;
y = zeros(length(etaspan),1);
f = @(x,eta) (x.^(1/2))./(1+exp(x-eta));

for eta = etaspan
   g = @(x) f(x,eta);
   y(i) = integral(g,0,500);
   i = i + 1;
end

f=y 
eta=etaspan 
save question_table.mat eta f

Just have MATLAB do the interpolation for you:

y_p = interp1(eta, y, eta_p);

interp1 uses linear interpolation by default, but can instead use higher order interpolation methods. Even with linear, your table seems much denser than necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM