Ales100
Ales100

Reputation: 175

How to create parametrized matrix

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

Upvotes: 0

Views: 52

Answers (1)

Thales
Thales

Reputation: 1316

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

Upvotes: 0

Related Questions