Decimal indexing for arrays in MATLAB

조회 수: 15 (최근 30일)
Yuvarajendra Anjaneya Reddy
Yuvarajendra Anjaneya Reddy 2023년 1월 10일
If I have a array of 11 elements, within the range 1 and 2, with a difference of 0.1, i.e, m = 1:0.1:2; to access the value of '1.4000' from the array 'm', the normal procedure is to write 'm(5)'. (index must be an integer)
Can I somehow index 'm(1.4)' and get the value 1.4000? (have a decimal value in the index)
  댓글 수: 3
Bjorn Gustavsson
Bjorn Gustavsson 2023년 1월 10일
Sometimes I see 1-D interpolation that way - this require the array to have some simple interpretation of samples of a sufficiently smooth function that the samples in the array can be used to build useful estimates for your "fractional" indices. But indexing is to elements you have.
Yuvarajendra Anjaneya Reddy
Yuvarajendra Anjaneya Reddy 2023년 1월 10일
편집: Yuvarajendra Anjaneya Reddy 2023년 1월 10일
@DGM Sorry for not being descriptive of my issue. I have a mesh grid [X,Y] = ndgrid (1:256, 1:256); and another matrix u = sin(X) + cos (Y); I have interpolated 10 values between every consequtive values in all the matrices.
If I need to access the value 'u' when X = 1.4, and Y = 2.8, i.e, u_interp(1.4, 2.8), then I have trouble, as I will have to create new Indices or run the interp2 command again to access the values. So, I thought decimal indexing would be a way..
[X,Y] = ndgrid (1:256, 1:256);
u = sin(X) + cos (Y);
%Interpolation
[Xq, Yq] = ndgrid(1:(1/10):256, 1:(1/10):256);
F = griddedInterpolant(X, Y, u, 'spline');
u_interp = F(Xq, Yq);

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

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2023년 1월 10일
Have a look at the help and documentation for griddedInterpolant. That function might be what you're looking for. It creates a function that interpolates over a gridded data. For repeated calls this means that it has kept the structure for interpolation such that you won't redo all the set-up you'd do with repeated calls to interp2 again and again with repeated calls.
HTH
  댓글 수: 1
Yuvarajendra Anjaneya Reddy
Yuvarajendra Anjaneya Reddy 2023년 1월 10일
@Bjorn Gustavsson Thank you for pointing me to the solution. This is what I was looking for.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by