Run a function into a function
Afficher commentaires plus anciens
Hi I have a function "a" called "function x=problem1(a,b,c,d)" I would like to create a function "b" that call function "a" and asign values to (a,b,c,d). Also, the function "b" have to run at least 6 times just with one call.
Réponse acceptée
Plus de réponses (4)
The question is not really clear. I assume that this is very basic and suggest to read the Getting Started chapters to learn the fundamentals of programming. But here a suggestion:
function b
for k = 1:6
a = rand;
b = 17.3;
c = k;
d = a + b + c ^ 2;
x = problem1(a,b,c,d);
disp(x);
end
Now look at the code and explain, what your problem is with any details.
Walter Roberson
le 21 Août 2017
0 votes
Your question is not clear. Under one interpretation, you should see https://www.mathworks.com/matlabcentral/answers/353428-bad-cell-reference-with-cell-array-of-function-handles#answer_278631
Adrian Quesada
le 21 Août 2017
Modifié(e) : Adrian Quesada
le 21 Août 2017
1 commentaire
Walter Roberson
le 21 Août 2017
Your existing code already handles the possibility that v will be a vector of length 5. Your existing code has b and c be optional. Are you talking about 5 different a values? If so, then would it be acceptable to just change
if v(k) == a
to
if ismember(v(k), a)
?
Adrian Quesada
le 21 Août 2017
0 votes
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!