Decimal indexing for arrays in MATLAB
Show older comments
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 Comments
What would be the point of getting the value in an array when, in order to get said value, you already know what it is?
This isn't real code, but hypothetically:
m = rand(100);
myindex = 0.504074886735144;
myvalue = m(myindex); % the result is either myindex or an error
In concept, this process accomplishes nothing except testing whether the value exists in the array.
On the other hand, maybe it's the location of the value that's important?
Bjorn Gustavsson
on 10 Jan 2023
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
on 10 Jan 2023
Edited: Yuvarajendra Anjaneya Reddy
on 10 Jan 2023
Accepted Answer
More Answers (0)
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!