|
"Steven Lord" <slord@mathworks.com> wrote in message <hdevvf$pmg$1@fred.mathworks.com>...
>
> "Hugh " <h_a_patience@hotmail.com> wrote in message
> news:hdenkv$fuv$1@fred.mathworks.com...
> > "Steven Lord" <slord@mathworks.com> wrote in message
> > <hdem2h$68c$1@fred.mathworks.com>...
> >>
> >> "Hugh " <h_a_patience@hotmail.com> wrote in message
> >> news:hdejdr$gi5$1@fred.mathworks.com...
>
> *snip*
>
> > Thank you so so much!!!
>
> *snip*
>
> > Res(1,:) = [c0 cn params y error error2 toc];
> > Res2(1,:) = [exitf];
> > Res3(1,:) = [optdata.firstorderopt];
> > Res4(1,:) = [optdata.iterations];
> > Res5(1,:) = [optdata.funcCount];
> > Res6(1,:) = [optdata.cgiterations];
>
> Are you sure these shouldn't be Res(z, :), Res2(z, :), etc. like your Res7,
> Res8, and Res9 assignment statements below? Although actually, take a look
> below for a better solution.
>
> > Res7(z,:) = [optdata.algorithm];
> > Res8(z,:) = [optdata.message];
> > Res9(z,:) = [Res Res2 Res3 Res4 Res5 Res6];
> >
> > end
> > end
> > end
> >
> > optim=find(Res(:,43)==min(Res(:,43)));
> >
> > toc;
> >
> > ??? Subscripted assignment dimension mismatch.
> > Error in ==> CurveGroups at 84
> > Res8(z,:) = [optdata.message];
> >
> > The complier thinks its a subscript problem but I can't understand how. It
> > happened on loop 34 the only difference between this and eaelier loops is
> > that optdata.message is returning a different error message
>
> All the rows of a matrix must have the same number of columns. As you've
> written it, if at one iteration the message is shorter than a previous
> message, it will try to fill in the zth row with a string containing fewer
> columns than Res8 has.
>
> As I said before, use cell arrays, something like:
>
> Res = cell(numberOfIterations, 9);
> for z = 1:numberOfIterations
> % Perform your calls
> Res{z, 1} = [c0 cn params ...
> Res{z, 2} = exitf;
> Res{z, 3} = ...
> ...
> Res{z, 8} = optdata.message;
> ...
> end
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>
Hi Steve,
I made the amendments re your earlier post, however, all that the cells in Res return is "[]". What as I doing wrong? (the altered code is shown below)
%% datafitting parameters
tic;
clc
close all
clear screen
%data= dlmread('yield.txt','\t');
data= dlmread('yield2.txt','\t');
ydata=data(2,:);
xdata=data(1,:);
%ydata=data(2:end,:);
%ydata=data(2,:);
%k=size(ydata);
%for i=1:k(1)
% xdata(i,:)=data(1,:);
% end
%x=eyes(2:end,:);oi
%xdata=data(1,:);
xdata2=[2 5 10 30];
%ydata2=[4.3 4.94 5.52 5.95];
ydata2=[4.21 4.6725 5.2375 5.715];
xdata3=data(1,:);
ydata3=data(2,:);
%c0 = [1.0 2 3 4];% starting values
%c0 = [1.0 1 1];
%lbn = [-Inf -Inf -Inf -Inf -Inf -Inf]; % lower bound
%ubn = [Inf Inf Inf Inf Inf Inf]; % upper bound
options = optimset('LargeScale','off','MaxFunEvals',1000000,'TolFun',1e-5,'MaxIter',1000000);
z=0;
for (i=0.01:5.01:25.1)
for (j=0.01:5.01:25.1)
for (k=0.01:1.01:5.01)
tic;
c0 = [5.95 1 1 1 i j 0.9 k 0.9 ];
%c0 = [1 1 1 1 1 0.1+i 0.9 0.9 0.9];
%c0 = [4.103594575 21.37812216 -66.97062464 0.079861881 1.81897068 -6.547214299 15.17678637 1.675525953 11.67454445];
%lbn = [-Inf -Inf -Inf -Inf i-0.00000001 j-0.00000001 -Inf k-0.00000001 -Inf]; % lower bound
%ubn = [Inf Inf Inf Inf i+0.00000001 j+0.00000001 Inf k+0.00000001 Inf];
lbn=[];
ubn=[];
z=z+1
% datafitting
%[cn,error]=lsqcurvefit(@PrimePerm,c0,xdata,ydata,lbn,ubn,options);
%[cn,error]=lsqcurvefit(@PrimePerm2,c0,xdata,ydata,lbn,ubn,options);
%[cn,error]=lsqcurvefit(@PrimePerm3,c0,xdata3,ydata3,lbn,ubn,options);
[cn,error,diff,exitf,optdata]=lsqcurvefit(@PrimePerm3,c0,xdata,ydata,lbn,ubn,options);
y=PW(xdata2,ydata2,cn(5),cn(6),cn(7),cn(8),cn(9));
params = y';
%params= [cn(1) cn(2) cn(3) cn(4) ];
params=[params cn(5) cn(6) cn(7) cn(8) cn(9)];
y=CRM(xdata3,params);
error2=(y-ydata3).^2;
error2 = sum(error2);
%Res(1,:) = [cn params error error2];
toc
Res=cell(180,9);
% Res(1,:) = [c0 cn params y error error2 toc];
% Res2(1,:) = [exitf];
% Res3(1,:) = [optdata.firstorderopt];
% Res4(1,:) = [optdata.iterations];
% Res5(1,:) = [optdata.funcCount];
% Res6(1,:) = [optdata.cgiterations];
% Res7(z,:) = [optdata.algorithm];
% Res8(z,:) = [optdata.message];
% Res9(z,:) = [Res Res2 Res3 Res4 Res5 Res6];
Inpts(z,:) = [c0 cn params y error error2 toc];
Res{z,1} = exitf;
Res{z,2} = optdata.firstorderopt;
Res{z,3} = optdata.iterations;
Res{z,4} = optdata.funcCount;
%Res6(1,:) = [optdata.cgiterations];
Res{z,5} = optdata.stepsize;
Res{z,6} = optdata.algorithm;
Res{z,7} = optdata.message;
%Res9(z,:) = [Res Res2 Res3 Res4 Res5 Res6];
end
end
end
%optim=find(Res{:,43}==min(Res{:,43}));
toc;
|