function that checks multiple numbers
Afficher commentaires plus anciens
%Greetings, Id like to write a function that will check multiple numbers in a %matrix insted of a single number. For example I have this function
function [output] = my_func(input)
output=[]
if mod(sqrt(input),1)==0
output=sqrt(input)
else
output=floor(input/3)
end
%but Id like to make it check multiple numbers instead of one?
1 commentaire
madhan ravi
le 15 Mar 2019
doc varargin
doc varargout
Réponses (1)
KSSV
le 15 Mar 2019
function [output] = my_func(input)
output = zeros(size(input)) ;
c = mod(sqrt(input,1)) ;
idx = c==0 ;
output(idx) = sqrt(input(idx)) ;
output(~idx) = floor(input(~idx)/3) ;
You need to re think on this line:
mod(sqrt(input),1)==0
3 commentaires
madhan ravi
le 15 Mar 2019
Modifié(e) : madhan ravi
le 15 Mar 2019
idx = c==0 ; % is completely redundant, there is no need for "==" equality
Reynaldo Ponce
le 15 Mar 2019
KSSV
le 15 Mar 2019
make input a matrix.
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!