How do I create an array of a function output?
Show older comments
How do I create an array of a function output? Each attempt I've tried it overwrites the value in the array and returns a 1x1 array with the final value calculated as it's value.
I've seen nested list functions or push functions? Which is the best for the below case and how do I implement it?
Apologies if this is a simplistic question, just struggling with this problem.
My function is:
>> m=0:1:3
>> n=0:1:4
>> for a=m
for b=n
res=ack(a,b)
end
end
function res=ack(m,n)
if m==0
res = n+1;
elseif m>0 && n==0
res = ack(m-1,1);
elseif m>0 && n>0
res = ack(m-1,ack(m,n-1));
end
end
1 Comment
David Fletcher
on 25 Feb 2018
Edited: Stephen23
on 26 Feb 2018
Essentially your problem is very similar to the answer I provided for
Maybe not the 'best' way to do it, but it is pretty much the answer to the problem you are outlining
Accepted Answer
More Answers (1)
Walter Roberson
on 25 Feb 2018
0 votes
1 Comment
FortuitousMonkey
on 26 Feb 2018
Categories
Find more on Matrix Indexing 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!