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

 채택된 답변

David Hill
David Hill 2020년 6월 17일

0 개 추천

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

Jonathan Pinko
Jonathan Pinko 2020년 6월 17일
Hi David,
Thanks for your response. When I attempted this method, I received the error message that MATLAB was unable to perform the assignment because the left and right sides have a different number of elements.
Do you know of any modifications I can make so that this error message does not occur?
David Hill
David Hill 2020년 6월 17일
Please provide your woof function.
Hi David,
Thanks again. I simplified my script in my initial question to streamline things. Here is my actual script, with the function I am focused on, "tigres", added as an attachment:
warning('off')
warning
Mgnum=75;
Mg0=82;
e=1
for y=1:numel(Mgnum)
for z=1:numel(Mg0)
if Mgnum(y)~=Mg0(z)
[Name]=puppies(Mgnum(y),Mg0(z));
if size(Name,1)>0
[SampleName(e),MeasuredFo(e),MeasuredD56Fe(e),MeasuredD26Mg(e),FeUncertainty(e),MgUncertainty(e),InterpD56Fe(e),InterpD26Mg(e),MagmaMgNum(e),OlivineFo(e),Temperature(e),Dtrsquared(e),DiffusionL(e),DiffusionCoef(e),years1mm(e)]=tigres(Mgnum(y),Mg0(z));
e=e+1;
end
end
end
end
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 2020년 6월 17일
편집: Jonathan Pinko 2020년 6월 17일
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 2020년 6월 17일
If you are satisfied with the answer, you should accept it to close out the question.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

2020년 6월 16일

댓글:

2020년 6월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by