Find the row position corresponding to a value
Show older comments
Please Find the value in column 1 that corresponds to the value in column 2.
for i=1:length(final_table1)
[r,c]=gyro_x(gyro_y(final_table1(1):final_table1(2)));
end
If you enter the above code, comes out like below
Array indices must be positive integers or logical values.
How can I find the value in column 1 that corresponds to the value in column 2?
(for example: If the value in column 2 is 30, column 1 needs a code that comes out as 5. Currently, only column 2 values can be found to fit the function.)
Answers (1)
Star Strider
on 14 May 2023
0 votes
I assume that ‘gyro_x’ and ‘gyro_y’ contain floating-point numbers, so that explains the error. Indexing into ‘gyro_x’ with ‘gyro_y’ will throw that error. However indexing into ‘gyro_y’ using that range of ‘final_table’ will always return the same result because it never changes. The ‘i’ loop count index is never used.
‘How can I find the value in column 1 that corresponds to the value in column 2?’
That would be easier to answer if we knew what ‘column 1’ and ‘column 2’ referred to.
.
3 Comments
minjoo CHOI
on 17 May 2023
column1 = [0:0.05:10]
column2 = rand()
For this particular value of column2, which specific value in column1 do you want to be returned and why do you choose that specific value? I suspect you want either interp1 with the 'nearest' interpolation method or discretize but I'm not 100% certain.
Star Strider
on 17 May 2023
@Steven Lord — Thank you!
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!