Run a function into a function
Mostra commenti meno recenti
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.
Risposta accettata
Più risposte (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
il 21 Ago 2017
0 voti
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
il 21 Ago 2017
Modificato: Adrian Quesada
il 21 Ago 2017
1 Commento
Walter Roberson
il 21 Ago 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
il 21 Ago 2017
0 voti
Categorie
Scopri di più su Characters and Strings in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!