Filter löschen
Filter löschen

how to call the function inside the looping function....?

9 Ansichten (letzte 30 Tage)
Dhines
Dhines am 4 Mär. 2013
for e.g..
while (....)
....
.....
...
function ...=...
.....
condition
end

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 4 Mär. 2013
"function" as a keyword is only used for defining functions, and cannot be used inside a loop (or inside an "if" or "switch" or other control statement.)
The only kinds of functions that can be defined within loops are anonymous functions.
If you are trying to call a function that you have previously defined, do not include the "function" keyword.
For example,
function r = d(a,b)
r = sqrt(a.^2 + b.^2);
end
could be called in a loop like
dist = inf;
while dist > 1/10
p = rand();
q = rand();
dist = d(p,q);
end

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by