Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Storing Cell Array in an Array

Subject: Storing Cell Array in an Array

From: Hugh

Date: 17 Oct, 2012 15:45:15

Message: 1 of 2

I am calling the function like so:

beta=NaN(size(rates,1),6);
mats=[1:50];
mats2=[2 5 10 30];
for i=1:2
y2=rates(i,mats2);
yM=rates(i,:);
dataList=struct('yM',yM,'mats',mats,'model',@NSS,'mats2',mats2,'y2',y2); de=struct('min',[0;3.5],'max',[3.5;30],'d',2,'nP',200,'nG',600,'ww',0.1,'F',0.5,'CR',0.99,'R',0,'oneElementfromPm',1); beta(i,:)=DElambdaVec(de,dataList,@OF);
end

However the output from DElabdavec, is a cell array:

output.Fbest=Fbest; output.xbest=xbest; output.Fbv=Fbv;

How can I store each of these items on each pass of the for loop?

Subject: Storing Cell Array in an Array

From: Hugh

Date: 17 Oct, 2012 19:30:29

Message: 2 of 2

"Hugh" wrote in message <k5mjqb$ge3$1@newscl01ah.mathworks.com>...
> I am calling the function like so:
>
> beta=NaN(size(rates,1),6);
> mats=[1:50];
> mats2=[2 5 10 30];
> for i=1:2
> y2=rates(i,mats2);
> yM=rates(i,:);
> dataList=struct('yM',yM,'mats',mats,'model',@NSS,'mats2',mats2,'y2',y2); de=struct('min',[0;3.5],'max',[3.5;30],'d',2,'nP',200,'nG',600,'ww',0.1,'F',0.5,'CR',0.99,'R',0,'oneElementfromPm',1); beta(i,:)=DElambdaVec(de,dataList,@OF);
> end
>
> However the output from DElabdavec, is a cell array:
>
> output.Fbest=Fbest; output.xbest=xbest; output.Fbv=Fbv;
>
> How can I store each of these items on each pass of the for loop?


The answer is (which was given to me)

You can save the results to a cell array - beta in this case:

beta{i} = DElambdaVec(de,dataList,@OF); Every element of beta is now an object returned by DElambdaVec, e.g.:

beta{1} ans = Fbest: 'Fbest' xbest: 'xbest' Fbv: 'Fbv' I used example values to create the entries here.

Note that you have to initialize beta=[] before the loop.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us