0

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
Ales100
  • 153
  • 1
  • 8

1 Answers1

0

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
Thales
  • 1,181
  • 9
  • 10
  • This is what I have now. But if I put B = create_matrix(A,N), then the matrix is probably allocated newly. I want to speed it up with knowledge of constant dimensions and relationships of parameters inside matrix B - so constant dimensions and variable values due to inserted parameter A. – Ales100 Jul 23 '23 at 12:51
  • please, add a minimal reproducible example of what you want. expected input and output and why this answer does not help you and what you have tried to do – Thales Jul 24 '23 at 22:03
  • In C langugage, allocation of memory would be something like below and then C[i] will contain pointers to members of A and B. If A and B changes, then C changes. const double* C = (double*) calloc(N, sizeof(double)); – Ales100 Jul 26 '23 at 18:35
  • @Ales100 That is what `B = zeros(1,n);` does: it allocates an array of N doubles and initializes it to zeros. – beaker Jul 28 '23 at 18:26
  • @beaker but it allocates it every function call -> every update. What I have shown allocates memory only once and then are changes solved by links. – Ales100 Jul 29 '23 at 19:22