How to create a 2D look-up table from vectors ?

1 次查看(过去 30 天)
Hello,
I would like to create a 2D look-up table from 3 vectors (size n x 1 each). Anyone have an idea about how could I do this please ?
First, we have in below the variation of 2 vectors (Temp, DCR) in function of vector SOC in range [0.25 - 0.9]
SOC = [0.25;0.3;0.35;0.4;0.45;0.5;0.55;0.6;0.65;0.7;0.75;0.8;0.85;0.9] ;
Temp = [1.8558;2.5549;3.4438;4.433;5.5271;6.5236;7.4795;8.4345;9.232;9.8256;10.4205;10.9303;11.3257;11.8103];
DCR = [0.0433;0.0598;0.0672;0.0749;0.0945;0.0991;0.0858;0.0857;0.0894;0.0788;0.0838;0.0815;0.0866;0.0971];
and Second, we have in below the variation of 2 vectors (SOC, DCR) in function of vector Temp in range [1.5 - 11.5]
SOC = [0.2222;0.2713;0.3038;0.3363;0.3605;0.3847;0.4089;0.433;0.4571;0.4811;0.505;0.5288;0.5603;0.584;0.6151;0.638;0.6695;0.7155;0.761;0.8135;0.865];
Temp = [1.5;2;2.5;3;3.5;4;4.5;5;5.5;6;6.5;7;7.5;8;8.5;9;9.5;10;10.5;11;11.5];
DCR = [0.0237;0.0582;0.0598;0.0659;0.0677;0.0843;0.0713;0.0731;0.0945;0.0777;0.0991;0.0821;0.0856;0.0892;0.0911;0.0767;0.066;0.0803;0.0684;0.0876;0.0778];
I want to know if it's possible, from datas above, to create a 2D look-up table of the parameter DCR in function of 2 parameters left such as SOC, Temp.
I've tried the command meshgrid and surf but it doesn't work.
Looking for your answers, Thank you a lot

回答(1 个)

Paxorus Sahay
Paxorus Sahay 2016-7-26
You can use containers.Map and use a vector of doubles as the key by converting it to a vector of chars. The class below will handle this key conversion for you. You can easily extend the class to handle more dimensions and other improvements, but it should solve the problem you currently have.
classdef DualKeyMap < handle
properties (Access = private)
map
end
methods
function obj = DualKeyMap(K1, K2, Val)
obj.map = containers.Map;
if nargin == 3 && length(K1) == length(K2) && length(K1) == length(Val)
for i = 1:length(K1)
key = convert(K1(i), K2(i));
obj.map(key) = Val(i);
end
end
end
function val = get(obj, k1, k2)
key = convert(k1, k2);
if obj.map.isKey(key)
val = obj.map(key);
else
val = [];
end
end
function [] = put(obj, k1, k2, val)
key = convert(k1, k2);
obj.map(key) = val;
end
end
end
function [key] = convert(k1, k2)
key = num2str([k1 k2]);
end
Example usage:
dkm = DualKeyMap(SOC, Temp, DCR)
dkm.get(0.2222, 1.5) % returns 0.0237
dkm.get(0.2222, 2) % returns []
  3 个评论
Paxorus Sahay
Paxorus Sahay 2016-7-28
Hi Nadia, a lookup table holds predetermined values. If you would like a function with the ability to interpolate, please refer to the Curve Fitting Toolbox.
Nadia A
Nadia A 2016-7-29
Hi, I have 2 arrays like the one in the example given. I want to generate a form similar to LUT and keep it. whenever I want to find a DCR value,I pass the current SOC point and the function would return the corresponding DCR even if that value of SOC is not present(through interpolation). Is this possible?
For curve fitting toolbox, you need a function between SOC and DCR ryt? Here I have only experimental observation points and not an exact relationship.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by