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

조회 수: 21 (최근 30일)
Sandeep Nair
Sandeep Nair 2022년 11월 22일
답변: Aditya Srikar 2023년 5월 26일
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
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일
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`.

카테고리

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