Find the row position corresponding to a value

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)

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

for example,
when
column 1 = [0:0.05:10];
column 2 = rand()
i should find find the value in column 1 that corresponds to the value in column 2
column1 = [0:0.05:10]
column1 = 1×201
0 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500 0.4000 0.4500 0.5000 0.5500 0.6000 0.6500 0.7000 0.7500 0.8000 0.8500 0.9000 0.9500 1.0000 1.0500 1.1000 1.1500 1.2000 1.2500 1.3000 1.3500 1.4000 1.4500
column2 = rand()
column2 = 0.7136
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.

Sign in to comment.

Categories

Tags

Asked:

on 14 May 2023

Commented:

on 17 May 2023

Community Treasure Hunt

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

Start Hunting!