I defined a function, let's say func(matrix_a, p, para)
for simplicity. When I use the function in a for loop, error "matrix_a not defined" comes up. But if the function is called several times without a for loop, it works well.
The function is a bot special. According to different p
, it will return a new matrix_a
. When I call it, I do it in the following way:
matrix_a = func(matrix_a, p, para)
which is like the matrix_a is updated. It may be concatenated with a new row or just added some numbers in some elements.
To be more specific, it returns "matrix_a not defined" when
para = ones(4)
matrix_a = zeros(2, 2)
for i = 1: 4
matrix_a = func(matrix_a, p, para[i])
end
It works well, when I test it:
para = ones(4)
matrix_a = zeros(2, 2)
i = 1
matrix_a = func(matrix_a, p, para[i])
i = 2
matrix_a = func(matrix_a, p, para[i])
i = 3
matrix_a = func(matrix_a, p, para[i])
i = 4
matrix_a = func(matrix_a, p, para[i])