MATLAB error: Output argument "variable" (and maybe others) not assigned during call to "function".

Hi experts,
I am getting this error: Output argument "ci" (and maybe others) not assigned during call to "Query_last_process" with the following function. I am totally clueless why this is happening. I checked most of the posted answers on this type of errors, but the problem in those posted questions was that the output variable was not getting assigned any value, thus resulting in the error. What is annoying in my case is that I don't even want to return the value of "ci", then where from is this error of "not assigning" appearing. Any comments or suggestion from the community would be very helpful.
The code:
function [ph,lmat,bmat,pmetr,dec,nph] = Query_last_process(N,ph,lmat,bmat,ri,ci,pmetr,Ls,finx,nfinx,cply)
n = log2(N);
isf = ismember(ri,finx);
if (isf==1)
nph=2^ph;
for pva=1:nph
ltem1 = lmat(pva,ri,ci);
if (ltem1<0)
pmetr(pva)=pmetr(pva)+abs(ltem1);
end
end
else
ph=ph+1;
nph=2^ph;
if (nph<=Ls)
for pva=1:nph/2
lmat(nph/2 + pva,:,:) = lmat(pva,:,:);
bmat(nph/2 + pva,:,:) = bmat(pva,:,:);
bmat(pva,ri,ci)=0;
bmat(nph/2+pva,ri,ci)=1;
pmetr(pva + nph/2) = pmetr(pva);
if (lmat(pva,ri,ci) < 0)
pmetr(pva) = pmetr(pva) + abs(lmat(pva,ri,ci));
else
pmetr(pva + nph/2) = pmetr(pva + nph/2)...
+ abs(lmat(pva,ri,ci));
end
end
else
pmetr(Ls+1:2*Ls) = pmetr(1:Ls);
for it1=1:Ls
if (lmat(it1,ri,ci) < 0)
pmetr(it1) = pmetr(it1) + abs(lmat(it1,ri,ci));
else
pmetr(it1+Ls) = pmetr(it1) + abs(lmat(it1,ri,ci));
end
end
[sdm, sdp] = sort(pmetr);
for it1=1:Ls
if (sdp(it1) <= Ls)
bestL(it1,:,:) = lmat(sdp(it1),:,:);
bestB(it1,:,:) = bmat(sdp(it1),:,:);
bestB(it1,ri,ci) = 0;
else
bestL(it1,:,:) = lmat(sdp(it1)-Ls,:,:);
bestB(it1,:,:) = bmat(sdp(it1)-Ls,:,:);
bestB(it1,ri,ci) = 1;
end
end
lmat = bestL;
bmat = bestB;
pmetr = sdm;
ph=log2(Ls);
nph = 2^ph;
end
end
if(ri==N)
for it1=1:Ls
uht(it1,:) = bmat(it1,nfinx,n+1);
end
dec = dc_func(uht,cply); %dc_func is a function
end
end

2 Comments

Please show the code line you are using to call this function.
Hi James,
Thanks so much for your reply. I am calling this function in a main program using the same code line as used in this function definition.
[ph,lmat,bmat,pmetr,dec,nph] =Query_last_process(N,ph,lmat,bmat,ri,ci,pmetr,Ls,finx,nfinx,cply)

Sign in to comment.

Answers (1)

It appears that the 5th output argument, dec, isn't always necessarily assigned by your function. It is only assigned if the condition ri==N is true. Could that be the variable that is not assigned for your call?
Also, what's the point of this for-loop at the end of your code?
for it1=1:Ls
uht(it1,:) = bmat(it1,nfinx,n+1);
end
Since uht is not an output variable, it is simply discarded when the function returns and the for-loop accomplished nothing.

3 Comments

Dear James,
Thanks for providing the insight. It is true that the 5th argument "dec" does not get assigned any value if the condition ri==N is not true. I am fixing that and will get back shortly. But the error is about the variable "ci".
Regarding the for-loop: If the condition ri==N is met, then I extract some data, store the data in the matrix "uht" and then pass this matrix for processing by another function "dc_func". This function "dc_func" gives me the output argument "dec".
uht: Yes, you are right and I missed that.
ci: I don't see how the message you quote could be about ci since that is not an output argument. Let's see what you get after fixing up the dec stuff.
Dear James,
Yes, it was because of "dec" variable. But I am clueless why MATLAB threw the error for "ci" variable when I was not even trying to return "ci". Wondering if that is a bug. Thanks so much for the help though!

Sign in to comment.

Asked:

on 27 Feb 2018

Edited:

on 28 Feb 2018

Community Treasure Hunt

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

Start Hunting!