- When the script is executed, the workspace used is usually the base workspace, and all variables are listed here only. Calling 'clear' will clear this base workspace. Hence, the results are expected here.
- When the script is made as a function file, the workspace is now specific to that particular function and not the base workspace. Also, calling 'clear' inside the function will clear the function workspace, not the base workspace. This is not an issue but just an output of different workspaces in the command window.
Unwanted "ans" value generated (comm.RSEncoder)
2 views (last 30 days)
I am encountering an unusual issue. In the following script if I don't make it a function everything works fine and I am getting a perfectly decoded message. But when I make it a function the decoded message and the "ans" bits aren't the same. All the values are assigned properly. I am not sure where the problem is arising.
Thank you in advance !
The corresponding output as an example is here:
function [sent,received] = ans_mf()
K=3; %%% variable
N=7; %%% variable
primPolyDegree = 3; %%% variable
% Create RS(7,3) encoder/decoder object
rsEnc = comm.RSEncoder(...
rsEnc.PrimitivePolynomialSource = 'Property';
rsEnc.PrimitivePolynomial = de2bi(primpoly(primPolyDegree,'nodisplay'),'left-msb');
rsDec = comm.RSDecoder(...
rsDec.PrimitivePolynomialSource = 'Property';
rsDec.PrimitivePolynomial = de2bi(primpoly(primPolyDegree,'nodisplay'),'left-msb');
bin_mess= randi([0 1],1,9);
bin_mess_transp = bin_mess' ;
message_in_bin_rsenc = rsEnc(bin_mess_transp);
if message_in_bin_rsenc(3,1) == 1
message_in_bin_rsenc(3,1) = zeros;
message_in_bin_rsenc(3,1) = 1;
message_in_bin_rsdec = rsDec(message_in_bin_rsenc);
sent = message_in_bin_rsenc';
received = message_in_bin_rsdec' ;
Ashutosh Singh Baghel on 17 Nov 2021
I understand you wish to know why there are different outputs when executing the script, usually and in function.
The resolution can be understood as follows -
While calling the function script from a command window, without specifying any output arguments, MATLAB automatically assigns a variable named 'ans' to the 'varargout.' Hence, you see the value stored in the 'sent' variable as stated in your function definition.