defining a range as a value for while loop

hi everybody I'm trying real hard for finding a way to define a range as a value to put it in a while loop and get a result but I have failed i'm doing it like this:
FX=(5*3.1416*M);
FM=(3*3.1416*M);
F=Wt/(KV*O*M*Y*(10^(-3)));
U=linspace(FM,FX,100);
while F~=U;
do some mathematics;
FX=(5*3.1416*M);
FM=(3*3.1416*M);
U=linspace(FM,FX,100);
F=Wt/(KV*O*M*Y*(10^(-3)));
end
when i insert the values it just says matlab is busy and no result shows up. i don't which part i am doing wrong. i'll be extremely thankful if you give a help

2 件のコメント

Adam
Adam 2015 年 11 月 26 日
編集済み: Adam 2015 年 11 月 26 日
You haven't really given enough information.
Is F a scalar?
U certainly isn't a scalar so you can't sensibly test:
F ~= U
in a loop. A scalar will never equal a vector and that isn't what you want to test anyway.
Are you trying to test if F is not a member of U or outside of the range it defines or something else?
ali najafi
ali najafi 2015 年 12 月 3 日
sorry
my bad
thank you for your answer
yes i want to test if F is not the a member of U

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2015 年 12 月 3 日

0 投票

while ~ismember(F, U)
is the test you asked for in your request "yes i want to test if F is not the a member of U". However, remember that ismember() does equality tests, so if F was even just 2^(-52) different than any member of U then ismember would not find it. I suspect what you want is
while F < FM | F > FX

3 件のコメント

ali najafi
ali najafi 2015 年 12 月 4 日
thank you for your answer
i'd much thankful if you answer me another question here, preventing me from making another thread
i want to define a set of numbers like this one:
x = [1,1.25,2,2.5,1.5,3,4,5,6,8,10,12,16,20,25,32,40,50];
and want to choose one of them randomly each time what should i do?
i have used this command for this job:
M=randi(length(x))
but it doesn't choose decimal numbers or sometimes gives me numbers that are not defined in my set of numbers
Adam
Adam 2015 年 12 月 4 日
Use that to give you indices into your array instead of the actual values. Then it will always give you one of your valid values as
x(M)
ali najafi
ali najafi 2015 年 12 月 4 日
thank you it really helped me

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by