I have a for loop inside a function Function. When I call that function within a script I get an error Index exceeds matrix dimensions and it points to a specific line of Function. This line of code that is pointed out corresponds to a for loop.
The for loop is built for following case:
I have two matrices of size.
B (400x30) C (1x30)
From these matrices I need to get a matrix A (400×30) that is obtained in the way
A(1,1) = B(1,1)*C(:,1)...A( 1,30) = B( 1,30)*C(:,30)A(2,1) = B(2,1)*C(:,1)...A(400,30) = B(400,30)*C(:,30)
The for loop I wrote in order to get A is following:
for p = 1:400; for i = 1:30; A(p,i) = C(p,i)*B(:,i); endend
Calling the function Function within a script I get the error, but if I go inside the function and evaluate the lines of code line by line, I don't get any error for the for loop, I can calculate the A matrix easily.
I really don't understand why is this happening, and I need to call Function within a script? But with getting this error constantly I can not move further with the code.
Many thanks,
Best Answer