Convert a three 10x2 matrix into a 2D lookup table data

I have a three 10x2 data in terms of a,b,c and i want to convert these data into 2D lookup table ie row should be a ,column should be b and the value to be lookup should be c,i tried doing interp2(x,y,z,xq,yq) but am getting an error of
Error using griddedInterpolant
Grid arrays must have NDGRID structure.
Can someone please help how to solve this issue

9 件のコメント

Matt J
Matt J 2022 年 11 月 22 日
編集済み: Matt J 2022 年 11 月 22 日
Not without a .mat file attachment with a,b,c.
Sandeep Nair
Sandeep Nair 2022 年 11 月 22 日
a=[
0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.16 0.16 0.16 0.16 0.16 0.15 0.15
0.33 0.32 0.32 0.31 0.31 0.31 0.30
0.49 0.48 0.48 0.47 0.47 0.46 0.45
0.65 0.64 0.64 0.63 0.62 0.61 0.60
0.82 0.81 0.80 0.79 0.78 0.76 0.75 ]
b=[
0.46 0.47 0.49 0.51 0.53 0.54 0.56
0.88 0.91 0.94 0.97 1.01 1.04 1.07
2.13 2.21 2.29 2.37 2.44 2.52 2.60
4.22 4.37 4.53 4.69 4.84 5.00 5.16
7.14 7.41 7.67 7.94 8.20 8.47 8.73
10.90 11.31 11.71 12.12 12.52 12.92 13.33 ]
c=[
0.14 0.15 0.15 0.15 0.15 0.15 0.16
0.15 0.15 0.15 0.15 0.16 0.16 0.16
0.15 0.15 0.16 0.16 0.16 0.16 0.16
0.15 0.16 0.16 0.16 0.16 0.17 0.17
0.16 0.16 0.16 0.17 0.17 0.17 0.17
0.16 0.16 0.17 0.17 0.17 0.17 0.18 ]
Sandeep Nair
Sandeep Nair 2022 年 11 月 22 日
Lets say this is the matrix
Dyuman Joshi
Dyuman Joshi 2022 年 11 月 22 日
You can do it with logical indexing as well.
a=[0.00 0.00 0.00 0.00 0.00 0.00 0.00;
0.16 0.16 0.16 0.16 0.16 0.15 0.15;
0.33 0.32 0.32 0.31 0.31 0.31 0.30;
0.49 0.48 0.48 0.47 0.47 0.46 0.45;
0.65 0.64 0.64 0.63 0.62 0.61 0.60;
0.82 0.81 0.80 0.79 0.78 0.76 0.75];
b=[0.46 0.47 0.49 0.51 0.53 0.54 0.56;
0.88 0.91 0.94 0.97 1.01 1.04 1.07;
2.13 2.21 2.29 2.37 2.44 2.52 2.60;
4.22 4.37 4.53 4.69 4.84 5.00 5.16;
7.14 7.41 7.67 7.94 8.20 8.47 8.73;
10.90 11.31 11.71 12.12 12.52 12.92 13.33];
c=[0.14 0.15 0.15 0.15 0.15 0.15 0.16;
0.15 0.15 0.15 0.15 0.16 0.16 0.16;
0.15 0.15 0.16 0.16 0.16 0.16 0.16;
0.15 0.16 0.16 0.16 0.16 0.17 0.17;
0.16 0.16 0.16 0.17 0.17 0.17 0.17;
0.16 0.16 0.17 0.17 0.17 0.17 0.18];
[m,n]=size(c);
x=randi(m)
x = 6
y=randi(n)
y = 1
c(abs(a-a(x,y))<1e-2&abs(b-b(x,y))<1e-2)
ans = 0.1600
c(x,y)
ans = 0.1600
Sandeep Nair
Sandeep Nair 2022 年 11 月 23 日
i want to input a random number which is should be inbetween the numbers in a and b and get the value from c, here instead of a random number indices are used to get the number
Dyuman Joshi
Dyuman Joshi 2022 年 11 月 23 日
What exactly would be a random number inbetween the numbers in a and b then?
Sandeep Nair
Sandeep Nair 2022 年 11 月 23 日
Random number would be like a=0.55 and b = 6.3 ,basically it should look for value if its not there then it should interpolate and give the answer in c
Dyuman Joshi
Dyuman Joshi 2022 年 11 月 23 日
Alright. In that sense, what if the value is a=0, b=0.5. Which value of c should be interpolated?
Similarly for a=0, b=0.52, c=?
Sandeep Nair
Sandeep Nair 2022 年 11 月 24 日
Here the condition which arise is a=0.45 and b=1.5 ,the condition which you are saying will not arise i want to interpolate between the points of the matrix

サインインしてコメントする。

回答 (1 件)

Aditya Srikar
Aditya Srikar 2023 年 5 月 26 日

0 投票

To create a 2D lookup table where the rows are values of `a`, the columns are values of `b`, and the entries are values of `c`, you can use MATLAB's `interp2` function. Here are the steps to do this:
1. Create a grid of `a` and `b` values using the `meshgrid` function in MATLAB:
[a_grid, b_grid] = meshgrid(a_values, b_values);
2. Use the `interp2` function to interpolate the values of `c` on this grid:
interp_c = interp2(a, b, c, a_grid, b_grid, 'spline');
Here, `inter_c` is the interpolated value of `c` on the grid, and the `'spline'` option specifies cubic spline interpolation.
Make sure that the dimensions of `a`, `b`, and `c` are the same and that there are no NaN or Inf values in `a`, `b`, or `c`.

カテゴリ

ヘルプ センター および File ExchangeInterpolation についてさらに検索

質問済み:

2022 年 11 月 22 日

回答済み:

2023 年 5 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by