How to create parametrized matrix

49 Views Asked by At

I would like to create parametrized matrix with given relationship between arguments like this:

B= @(A) [1*A(1), 2*A(2), 3*A(3), 4*A(4)];

But matrix is huge and cannot be created by constant expression like this. I need something like this:

for i=1:N
    B(i) = @(A) i*A(i);
end

Creating matrix this way is not possible and the cell array did not helped me, because this (bellow) is also not valid.

B = @(A) cell(1,N);
for i=vec
    B(i) = @(A) i*A(i);
end
1

There are 1 best solutions below

5
Thales On

What about creating a function?

function B = create_matrix(A,n)
    B = zeros(1,n);
    for ii=1:n
        B(ii) = ii*A(i);
    end
end