MATLAB Answers

Concatenate Results from Function

1 view (last 30 days)
Jonathan Pinko
Jonathan Pinko on 16 Jun 2020
Commented: David Hill on 17 Jun 2020
I have the following script:
Apples=1:1:5;
Bananas=10:1:15;
for a=1:numel(apples)
for b=1:numel(bananas)
[lions,tigers,bears]=woof(apples(a),bananas(b));
end
end
In which woof is a function that I am calling.
When I run this function, only the final results of lions, tigers, and bears are stored in my workspace. Instead, I would like to vertically concatenate all of my results of lions, tigers and bears, from all of my values of apples and bananas. In doing so, I would have 3 separate vectors, one each for lions, tigers, and bears, stored in my workspace.
How would I do this?
Thanks,
Jonathan

  0 Comments

Sign in to comment.

Accepted Answer

David Hill
David Hill on 17 Jun 2020
apples=1:1:5;
bananas=10:1:15;
c=1;
for a=1:numel(apples)
for b=1:numel(bananas)
[lions(c),tigers(c),bears(c)]=woof(apples(a),bananas(b));
c=c+1;
end
end

  6 Comments

Show 3 older comments
David Hill
David Hill on 17 Jun 2020
Are all you outputs scalar? Or are they vectors, or matrices? You need to look at the sizes of each of your outputs (will each of them always be the same size?) and adjust accordingly. If you provide your excel spread sheets, I might be able to help.
SampleName(:,e);%if row vector output
SampleName(e,:);%if column vector output
SampleName(e);%if scalar output
SampleName(:,:,e);%if matrix output
Jonathan Pinko
Jonathan Pinko on 17 Jun 2020
Ah, this works perfectly. Some of the outputs were scalars, while others were column vectors, so I had to manipulate it in that way. Thanks for the help.
David Hill
David Hill on 17 Jun 2020
If you are satisfied with the answer, you should accept it to close out the question.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!