G0064 : Operand missing

Hi I am tyrying to run one of the examples on GUASS tutorial pages which is as below:

rint = ceil(1e6 * rndu(2000, 1));

//Create vector to hold sample samp = zeros(2000, 1); //Sampling with replacement for j(1, 2000 1); idx = rint[j]; samp[j,.] = A[idx,.]; endfor;

 

But it gives me an error saying:

G0064 : Operand missing

 

Can someone please help me fix the error?

 

Thanks,

 

1 Answer



0



There appears to be a missing comma in the 'for' statement (fixed now in the tutorial). Here is the correct code:

rint = ceil(1e6 * rndu(2000, 1));

//Create vector to hold sample
samp = zeros(2000, 1);

//Sampling with replacement
for j(1, 2000, 1);
    idx = rint[j];
    samp[j,.] = A[idx,.];
endfor;

Also note, that you will need to create a matrix A before this from which to take samples. Here is a fully working example:

nobs = 1e6;
nvars = 5;

//Sample matrix to draw from
A = rndn(nobs, nvars);

rint = ceil(nobs * rndu(2000, 1));

//Create vector to hold sample
samp = zeros(2000, nvars);

//Sampling with replacement
for j(1, 2000, 1);
    idx = rint[j];
    samp[j,.] = A[idx,.];
endfor;

It is also helpful to know that in GAUSS 16 and newer, there is a function to take random samples with or without replacement. Here are two simple examples of that:

nobs = 1e6;
nvars = 5;

//Sample matrix to draw from
A = rndn(nobs, nvars);

//Sample without replacement
samp = sampleData(A, 2000);

//Sample with replacement
samp_wr = sampleData(A, 2000, 1);

aptech

1,773

Your Answer

1 Answer

0

There appears to be a missing comma in the 'for' statement (fixed now in the tutorial). Here is the correct code:

rint = ceil(1e6 * rndu(2000, 1));

//Create vector to hold sample
samp = zeros(2000, 1);

//Sampling with replacement
for j(1, 2000, 1);
    idx = rint[j];
    samp[j,.] = A[idx,.];
endfor;

Also note, that you will need to create a matrix A before this from which to take samples. Here is a fully working example:

nobs = 1e6;
nvars = 5;

//Sample matrix to draw from
A = rndn(nobs, nvars);

rint = ceil(nobs * rndu(2000, 1));

//Create vector to hold sample
samp = zeros(2000, nvars);

//Sampling with replacement
for j(1, 2000, 1);
    idx = rint[j];
    samp[j,.] = A[idx,.];
endfor;

It is also helpful to know that in GAUSS 16 and newer, there is a function to take random samples with or without replacement. Here are two simple examples of that:

nobs = 1e6;
nvars = 5;

//Sample matrix to draw from
A = rndn(nobs, nvars);

//Sample without replacement
samp = sampleData(A, 2000);

//Sample with replacement
samp_wr = sampleData(A, 2000, 1);

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.