How to create a 2D lookUp table in matlab

조회 수: 113 (최근 30일)
Nadia A
Nadia A 2016년 8월 2일
댓글: Walter Roberson 2017년 9월 8일
I want to create a 2D look Up table from 3 arrays
x1= 0:0.1:1 %axis values --> length is 11
x2= 25:2:35 %axis values --> length is 6
y= 0.01:0.001:0.06 % output data --> length is 51, rest of the 15 elements are zeros
I want to create an LUT which has 6 rows and 11 columns. Whenever I need to retrieve y, if exact query points of x1 and x2 is not present, then the function should give an interpolated value. I want to generate a .m script for this without using Simulink.
Anyone please help me with this.
Thanks
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 8월 2일
length(y) is 51. If you were given the J'th x1 value exactly and the K'th x2 value exactly (so no interpolation needed), which of the 51 y values should be output?
Nadia A
Nadia A 2016년 8월 2일
편집: Nadia A 2016년 8월 2일
Sorry, rest of the values is assigned as 0.I have edited my original post.
Thanks

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

채택된 답변

Stephen23
Stephen23 2016년 8월 2일
You could use interp2 or interpn:
>> x1 = 0:0.1:1;
>> x2 = 25:2:35;
>> y = 0.01:0.001:0.06;
>> vm = zeros(numel(x1),numel(x2));
>> vm(1:numel(y)) = y;
>> interpn(x1,x2,vm,0,25)
ans = 0.010000
Note that this allocates the values of y row-wise into mat. If you want them to be allocated column-wise then transpose mat before and after the allocation.
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 9월 8일
You need a scattered interpolant for that case. You should expect that off-diagonal might look fairly different than you imagine, as interpolation will come to depend upon which triangle happens to be closest in 3 space.

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

추가 답변 (1개)

Satishkumar Aruljothi
Satishkumar Aruljothi 2016년 8월 2일
편집: Satishkumar Aruljothi 2016년 8월 2일
Use 2-D looup table from simulink library.
see the attached image.
  댓글 수: 1
Nadia A
Nadia A 2016년 8월 2일
편집: Nadia A 2016년 8월 2일
Hi SatishKumar, Is there any matlab function for this? I need to implement this same functionality in .m script without using Simulink.
Thanks

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

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by