MATLAB: Simple Matrix operation using for loop

#matrixoperation

Hello all, I want to do following matrix operation, I have two matrices y and errorsample as: y=y=[0.53, 0.6, 0.58, 0.68, 0.85, 0.85];1X6 matrix errorsample=normrnd(0,stdev,1,1e4);1X1e4 matrix
Now I want to create new matrix Y (1e4X6) such that Y(i)(j)=y(j)-errorsample(i)
For that I have written following code: y=[0.53, 0.6, 0.58, 0.68, 0.85, 0.85]; stdev=0.0523; errorsample=normrnd(0,stdev,1,1e4); for i=1:1:1e4; for j=1:1:6; Y(i)(j)=y(j)-errorsample(i); end end
but after running this, I am getting following error: ??? Error: File: Q4.m Line: 23 Column: 5 ()-indexing must appear last in an index expression.
Can anybody please tell me how to debug this problem, It's urgent Thanks in advance,
Nikhil

Best Answer

Maybe you want
y=[0.53, 0.6, 0.58, 0.68, 0.85, 0.85];
stdev=0.0523;
errorsample=normrnd(0,stdev,1,1e4);
out=zeros(1e4,6);
for i=1:1:1e4;
for j=1:1:6;
out(i,j)=y(j)-errorsample(i);
end
end
disp(out)