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개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

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