whos
Name Size Bytes Class Attributes
eff_map 500x500 2000000 double
x_voltage 500x500 2000000 double
y_current 500x500 2000000 double
We are given some data as arrays, and you understand how to use griddedInterpolant. What you need to learn next is about building a function handle.
F = griddedInterpolant(x_voltage,y_current,eff_map)
Now, you want to reduce that, for a FIXED voltage, to a function of only one variable. Since 42 is the answer to everything, I'll fix the voltage at 42.
FixedVolts = 42;
F_v42 = @(y) F(repmat(FixedVolts,size(y)),y);
That is all it takes. We can now evaluate the new function at some value or a list of values for the current. We can even plot it as a function of one variable now. I've even set up F_42v in such a way that we can even pass in a complete vector or array for y. The result will be the same shape and size as the input for y.
F_v42(17)
ans =
0.881963765526607
F_v42([1 3 5])
ans =
0.0952082740655224 0.230322190630928 0.381508409480828
fplot(F_v42,[0,50])
xlabel 'y_current'
ylabel 'eff_map @ x = 42'
Best Answer