Run a function into a function
Show older comments
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.
Accepted Answer
More Answers (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
on 21 Aug 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
on 21 Aug 2017
Edited: Adrian Quesada
on 21 Aug 2017
1 Comment
Walter Roberson
on 21 Aug 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
on 21 Aug 2017
0 votes
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!