Is there something wrong with this function?

It is supposed to figure out if the number is whole or not. if not it rounds down, if it is it squares.
function [remainder]=data_modifier(data1)
remainder=rem(data1,1)
if remainder==0
sqrt(data1)
else
floor(data1)
end
end

2 个评论

No error. Why?
However, change your output of function, i guess remainder is not the output you wanted.
No it’s not correct if the input is float ,it fails

请先登录,再进行评论。

 采纳的回答

function [result]=data_modifier(data1)
if isfloat(data1)==1
sqrt(data1)
else
floor(data1)
end
end

5 个评论

The above shows if the number is a decimal it takes square root if not it rounds
okay thank you! that is a smart way to do it.
Anytime, accept the answer so that people know problem is solved
Hi jonathan,
change your function output to
function ans = data_modifier(data1)
never name an output as ans because it will contradict with the mat labs inbuilt variable named as ans

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by