Reusing a changed variable

2 次查看(过去 30 天)
mohamed madani
mohamed madani 2016-12-6
So I have a function which returns to me a value for X and Y. I need a way to change the Y value to get a certain X value. The function does not allow me to just choose an X value because the values of X and Y are not related in a linear way or any other way. That's why I need a way to change the Y value little by little (for example from 1500 to 1510 then 1520..... and so on) and each time checking if the X value has reached the required value or has come really close to it (withing 5 integers either side). Would really appreciate an answer for this problem. Thanks in advance
EDIT: i need to clarify some things. The function is a histcount which uses values of Y and sorts them into bins X. I found the max Y value and found the corresponding bin number, but now I need to change the input which is a different variable (lets call it Z) in a way that changes the bin number with the max Y to lets say 350. When I use Z=1500, It returns values of X=293 and Y=(some other irrelevant value. I need a way to change Z automatically so the function can search for the Z value that returns an X(bin) value close enough to 350. Sorry for the first explanation. Its kinda difficult to explain it all.
  1 个评论
John D'Errico
John D'Errico 2016-12-6
编辑:John D'Errico 2016-12-6
Huh? You say that your function returns both X AND Y.
How can you now change Y? You talk about changing Y to some other value, but you give us no clue as to how you will change it, since it is apparently an OUTPUT of the function.
Are there other parameters that control these values? How many of them are you able to change?
Or is the problem really one where you have a function X=f(Y)? In that case, one could just use fzero, except that apparently these are integers. Maybe. It is hard to tell.
The crystal ball is so foggy. We cannot read your mind, so we can only go by what you tell us. An when what you tell us is garbled beyond comprehension, how can you expect an answer?

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2016-12-6
The important sentence is:
X and Y are not related in a linear way or any other way
Then the wanted result can 1500.00000000007 and if you simply try to vary the input from 1500 to 1510, it is extremely time consuming to find the solution. Even the "5 integers on both sides" does not help as long as there is no relation between X and Y. Therefore pure guessing is currently the best approach.
If you are convinced, that there is a better solution, please clarify this by editing the original question (not as a comment).
  1 个评论
mohamed madani
mohamed madani 2016-12-7
I updated my question. I think I might be able to do it with for loops and if statements.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by