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 件のコメント

Kevin Chng
Kevin Chng 2018 年 10 月 23 日
編集済み: Kevin Chng 2018 年 10 月 23 日
No error. Why?
However, change your output of function, i guess remainder is not the output you wanted.
madhan ravi
madhan ravi 2018 年 10 月 23 日
No it’s not correct if the input is float ,it fails

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

 採用された回答

madhan ravi
madhan ravi 2018 年 10 月 23 日
編集済み: madhan ravi 2018 年 10 月 23 日

0 投票

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

5 件のコメント

madhan ravi
madhan ravi 2018 年 10 月 23 日
The above shows if the number is a decimal it takes square root if not it rounds
Jonathan Cohen
Jonathan Cohen 2018 年 10 月 23 日
okay thank you! that is a smart way to do it.
madhan ravi
madhan ravi 2018 年 10 月 23 日
編集済み: madhan ravi 2018 年 10 月 23 日
Anytime, accept the answer so that people know problem is solved
Kevin Chng
Kevin Chng 2018 年 10 月 23 日
編集済み: Kevin Chng 2018 年 10 月 23 日
Hi jonathan,
change your function output to
function ans = data_modifier(data1)
madhan ravi
madhan ravi 2018 年 10 月 23 日
編集済み: madhan ravi 2018 年 10 月 23 日
never name an output as ans because it will contradict with the mat labs inbuilt variable named as ans

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

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2018 年 10 月 23 日

編集済み:

2018 年 10 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by