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
采纳的回答
Remove sprintf()
13 个评论
And in fact your if else can be replace with
Condition = y > .6 % 1 means true and 0 means false
This is only working for one condition
Huh? More illustrations needed with an example. Because the comment is totally vague.
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
a=rand(1)
round(0.333)
the answer is 0 I wnat 0.3
Read the input arguments of that function in documentation ;).
>> round(.3555,1)
ans =
0.4000
>>
no sir any of your suggestion is not working
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 ?
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.
Thanks Steven.
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!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 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)
