Why function need more variables
Afficher commentaires plus anciens
(I'm a beginner of matlab. )
I try to make a matlab sub-function to analysis the frequency of our lab data,however,matlab always display "Not enough input arguments."
I can't fix error of my program.
What should I add or change?
function f = freq(time,data)
t = time;
d = data;
max = islocalmax(data);
dmax = d(max);
tmax = t(max); %the t of vmax
for i = 1 : length(dmax)-2
period(i) = tmax(i+2) - tmax(i);
end
f = 1/mean(period);
end
Réponses (1)
madhan ravi
le 8 Août 2019
Modifié(e) : madhan ravi
le 8 Août 2019
time = ... some values
data = ... some values
f = freq(time,data) % this is how you call a function
Google "how to call a function MATLAB?"
Note: Don't use max as variable name because MATLAB has an inbuilt function named max()
2 commentaires
Zih-Sian Yang
le 8 Août 2019
Modifié(e) : Zih-Sian Yang
le 8 Août 2019
madhan ravi
le 8 Août 2019
Modifié(e) : madhan ravi
le 8 Août 2019
https://in.mathworks.com/help/matlab/math/parameterizing-functions.html - the link shows you how to parameterize a function , plus you need to call the function properly with passing in the adequate amount of arguments to the function as shown in the answer above. Don‘t use global!, it’s completely avoidable.
Catégories
En savoir plus sur Variables 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!