user3509716
user3509716

Reputation: 69

How to use find function to find a specific coordinate?

For Matlab, I've been given a function y= 3x+4 I need to find the x value when y = 25000 using the 'find' function. I've tried x = find(y == 25000) and receive nothing. I know the function returns index of nonzero values. But not sure how to use it in this context.

Upvotes: 0

Views: 131

Answers (2)

Daniel1000
Daniel1000

Reputation: 797

You should look for the best match instead of an exact result:

x = 0:0.1:50000;
y = 3*x+4;
[value,index] = min(abs(y-25000))
x(index)
y(index) 

Upvotes: 1

Dennis Jaheruddin
Dennis Jaheruddin

Reputation: 21563

This would typically require solve, as you are trying to solve an equation.

Unless you already had a vector with the correct value, in that case you could use find like so:

x = 0:25000
y = 3*x+4

x(find(y==25000))

Make sure to check doc find and doc solve to understand what they both do.

Upvotes: 3

Related Questions