why this code not displaying else part
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
the following code is only displaying the if part even if the value is less than 0.6
y = sprintf('%.1f',rand(1))
if y>0.6
disp('the value is false')
else
disp('true')
end
採用された回答
madhan ravi
2020 年 6 月 7 日
Remove sprintf()
13 件のコメント
And in fact your if else can be replace with
Condition = y > .6 % 1 means true and 0 means false
abdul rehman
2020 年 6 月 7 日
This is only working for one condition
madhan ravi
2020 年 6 月 7 日
Huh? More illustrations needed with an example. Because the comment is totally vague.
abdul rehman
2020 年 6 月 7 日
actually I want a random number btween 0 and1 the code give me answer like 0.3555 which is 4 decimal place, so i want to round it of to 0.3 and that use same random number in condition
doc round
abdul rehman
2020 年 6 月 7 日
a=rand(1)
round(0.333)
the answer is 0 I wnat 0.3
madhan ravi
2020 年 6 月 7 日
編集済み: madhan ravi
2020 年 6 月 7 日
Read the input arguments of that function in documentation ;).
>> round(.3555,1)
ans =
0.4000
>>
abdul rehman
2020 年 6 月 7 日
no sir any of your suggestion is not working
madhan ravi
2020 年 6 月 7 日
A totally vague comment not useful to understand at all.
madhan ravi
2020 年 6 月 7 日
編集済み: madhan ravi
2020 年 6 月 7 日
”madhan ravi your answars are incomplete“
Yes because it’s your homework and not mine. Don’t expect others to do your homework. Make sure to READ the documentations properly before bashing others!
”you must know round only take single argument. Sorry but you are wasting time and your as well“
Not sure who’s wasting whose time here.Did you even read the documentation ?
Steven Lord
2020 年 6 月 7 日
As of release R2014b the round function has a syntax that accepts multiple inputs. abdul rehman, are you using a release prior to release R2014b? If so that would explain why madhan ravi's suggestion didn't work for you.
madhan ravi
2020 年 6 月 7 日
Thanks Steven.
abdul rehman
2020 年 6 月 7 日
thanks Steven this was the actural issue. and sorry madhan
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Data Type Conversion についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
