My matlab code is giving me this error "Too many outputs requested". If someone can help me solve this?
1 view (last 30 days)
Show older comments
My code is as follows:
function nn_ewn=optim_ewn(c_ewn)
case_ewn=case_one_ewn_gen(c_ewn);
a_cost=[];
for ii=1:1:size(case_ewn,2)
tmp_ewn=case_ewn{ii};
[t_cost t_Ic t_current t_a2]=find_cost(tmp_ewn);
u=fitdist(t_Ic,'normal');
wu=u.sigma; wn=u.mu;
u_arr=[]; cost_arr=[]; count=1;
while 1
ste=sum(tmp_ewn);
tmp2_ewn=tmp_ewn;
Hy=t_Ic-wn;
v1=max(Hy); v1_pos=find(Hy==v1);
v2=min(Hy); v2_pos=find(Hy==v2);
v4_pos=find(t_Ic==max(t_Ic));
v5_pos=find(t_Ic==min(t_Ic));
Ht=sort(t_Ic(:));
v6_pos=find(t_Ic==Ht(2));
d=1;
tmp3_ewn=tmp2_ewn;
if (tmp2_ewn(v1_pos) == 4 && tmp2_ewn(v2_pos) == 4) || (tmp2_ewn(v1_pos) == 12 && tmp2_ewn(v2_pos) == 12)
if (tmp2_ewn(v5_pos) == 4 && tmp2_ewn(v6_pos) == 4) || (tmp2_ewn(v5_pos) == 12 && tmp2_ewn(v6_pos) == 12)
tmp3_ewn=tmp2_ewn;
break
elseif (tmp2_ewn(v5_pos) == 4 && tmp2_ewn(v6_pos) ~= 4) || (tmp2_ewn(v5_pos) ~= 12 && tmp2_ewn(v6_pos) == 12)
tmp3_ewn(v5_pos)=tmp2_ewn(v5_pos)+d;
tmp3_ewn(v6_pos)=tmp2_ewn(v6_pos)-d;
elseif (tmp2_ewn(v5_pos) ~= 4 && tmp2_ewn(v6_pos) == 4) || (tmp2_ewn(v5_pos) == 12 && tmp2_ewn(v6_pos) ~= 12)
tmp3_ewn(v5_pos)=tmp2_ewn(v5_pos)-d;
tmp3_ewn(v6_pos)=tmp2_ewn(v6_pos)+d;
end
elseif (tmp2_ewn(v1_pos) == 4 && tmp2_ewn(v2_pos) ~= 4) || ...
(tmp2_ewn(v1_pos) ~= 4 && tmp2_ewn(v2_pos) == 4) || (tmp2_ewn(v1_pos) ~= 4 && tmp2_ewn(v2_pos) ~= 4) || ...
(tmp2_ewn(v1_pos) == 12 && tmp2_ewn(v2_pos) ~= 12) || ...
(tmp2_ewn(v1_pos) ~= 12 && tmp2_ewn(v2_pos) == 12) || (tmp2_ewn(v1_pos) ~= 12 && tmp2_ewn(v2_pos) ~= 12)
if (min(tmp2_ewn) >= 4 || max(tmp2_ewn) <= 12) && ...
(tmp2_ewn(v4_pos) >= 4 || tmp2_ewn(v5_pos) <= 12)
tmp3_ewn(v1_pos)=tmp2_ewn(v1_pos)-d;
tmp3_ewn(v2_pos)=tmp2_ewn(v2_pos)+d;
if tmp3_ewn(v1_pos) < 4 || tmp3_ewn(v2_pos) > 12
for jj=1:1:length(t_Ic)
v3_pos=find(t_Ic==Ht(jj)); % v3_pos is second minimum
if (tmp2_ewn(v3_pos) == 4) || (tmp2_ewn(v3_pos) == 12) %R
tmp_ewn=tmp2_ewn;
continue
elseif (tmp2_ewn(v3_pos) ~= 4 && tmp2_ewn(v3_pos) >= 4)|| (tmp2_ewn(v3_pos) ~= 12 && tmp2_ewn(v3_pos) <= 12)
tmp3_ewn(v3_pos)=tmp2_ewn(v3_pos)+d;
% tmp3_ewn(v3_pos)=tmp2_ewn(v3_pos)-d;
tmp3_ewn(v4_pos)=tmp2_ewn(v4_pos)-d;
break
end
end
end
end
end
if min(tmp3_ewn) < 4
n=length(tmp3_ewn);
tmp3_ewn(v4_pos)=4;
tmp3_ewn(n)=ste-sum(tmp3_ewn(1:end-1));
end
if max(tmp3_ewn) > 12
n=length(tmp3_ewn);
tmp3_ewn(v5_pos)=12;
tmp3_ewn(n)=ste-sum(tmp3_ewn(1:end-1));
end
tmp3_ewn
[g_cost g_Ic g_current g_a2]=find_cost(tmp3_ewn);
u1=fitdist(g_Ic,'normal');
if wu > u1.sigma
wu=u1.sigma
tmp_ewn=tmp3_ewn;
u_arr(count)=u1.sigma
cost_arr(count)=g_cost
g_Ic_cell{count}=g_Ic;
tmpe_cell{count}=tmp3_ewn';
cost_arr
count=count+1;
continue
elseif wu < u1.sigma
u_m_pos=find(u_arr == min(u_arr));
gt_ewn=tmpe_cell{u_m_pos};
gt_cost=cost_arr(u_m_pos);
gt_Ic=g_Ic_cell{u_m_pos};
break
end end
a_cost=[a_cost,gt_cost];
Ic_cell{ii}=gt_Ic;
n_ewn{ii}=gt_ewn;
end
n=length(n_ewn)
a_cost
mp_pos=find(a_cost==min(a_cost));
nn_ewn=n_ewn{mp_pos};
Error is..:
Too many outputs requested. Most likely cause is missing [] around
left hand side that has a comma separated list expansion.
Error in optim_ewn (line 98)
gt_ewn=tmpe_cell{u_m_pos};
Can someone help me solve this problem. Thank you.
0 Comments
Answers (2)
Jan
on 17 Oct 2017
u_m_pos=find(u_arr == min(u_arr));
gt_ewn=tmpe_cell{u_m_pos};
The message appears, if the minimal value min(u_arr) appears more than once inside u_arr.
If you want the index of one minimum only:
[~, u_m_pos] = min(u_arr);
0 Comments
Stephen23
on 17 Oct 2017
There is nothing preventing you from having zero, one, or more values returned. You need to take into account those situations. One solution is to simply return a subset of the cell array:
gt_ewn = tmpe_cell(u_m_pos);
Read more about cell array indexing here:
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!