How to reduce dimension of griddedinterpolant?

1 view (last 30 days)
I have a gridded efficiency map where each point depends on different input values for current and voltage.
F = griddedInterpolant(x_voltage,y_current,eff_map)
% and query points
eff = F(voltage_set,current_set)
Now I want to convert this map while runtime of a program to a curve for a fixed voltage, so that the efficiency just depends on the current/power.
Kind of,
function new_F = reduceDimension(F,fixed_voltage)
...
end
eff = new_F(power_set)
I can't find a quick solution, maby someone has an idea.
THX

Accepted Answer

John D'Errico
John D'Errico on 29 Jul 2020
Edited: John D'Errico on 29 Jul 2020
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'
  1 Comment
Konrad Warner
Konrad Warner on 29 Jul 2020
Perfect, thanks!
Just, to get rid of the original map data I create a new griddedInterpolant with reduced dimentions by using output arguments of fplot, or speaks something against it?
[x,y] = fplot(F_v42,[0,50])
F_v42 = griddedInterpolant(x,y)
The result looks fine, but I get a lot of warnings using fplot. No idea what that means.
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your
function to return an output with the same size and shape as the input arguments.
> In matlab.graphics.function.FunctionLine>getFunction
In matlab.graphics.function/FunctionLine/updateFunction
In matlab.graphics.function.FunctionLine.set.Function_I
In matlab.graphics.function.FunctionLine.set.Function
In matlab.graphics.function.FunctionLine
In fplot>singleFplot (line 245)
In fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 200)
In fplot>vectorizeFplot (line 200)
In fplot (line 166)
Warning: Having two output arguments for fplot will be removed in a future release. Use the XData and YData
properties instead.
> In fplot (line 180)

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!