Run a function into a function
显示 更早的评论
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.
采纳的回答
更多回答(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
2017-8-21
0 个投票
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
2017-8-21
编辑:Adrian Quesada
2017-8-21
1 个评论
Walter Roberson
2017-8-21
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)
?
类别
在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!