jeudi 23 avril 2015

Apply different functions to columns of a matrix

I have a matrix, for example, "A", with size 5 * n, where "n" is a large number. I want to apply functions to the columns of "A", is for loop the best solution?

To be specific, assume

A = randn(5, 10000);
B = randn(5, 5000);
ix = cell(ix_1, ix_2, ...);

and I want to do the following:

for i = 1:10000
    A(:, i) = B(:, ix_i) * B(:, ix_i)' * A(:,i);

The function in this example is just B(:, ix_i) * B(:, ix_i)' and "ix" is a cell of vectors which are indices, for example, "ix_i" could be [1, 3, 11, 20].

Aucun commentaire:

Enregistrer un commentaire