Borrar filtros
Borrar filtros

Divide each column by a constant from a vector

17 visualizaciones (últimos 30 días)
Frederik Bjerregaard
Frederik Bjerregaard el 5 de Mzo. de 2022
Comentada: Frederik Bjerregaard el 5 de Mzo. de 2022
I have a matrix A that has the format 150000x8 and a vector B of the format 1x8. I want to create a function that divide every value in the first column of the matrix by the first value from the matrix, the 2nd column with the second value and so on. Is there anyway to write this in one line or should i code it individually for each column?

Respuesta aceptada

Voss
Voss el 5 de Mzo. de 2022
Editada: Voss el 5 de Mzo. de 2022
A = randn(150000,8);
B = randn(1,8);
C = A./B; % this should be all you have to do*
size(C)
ans = 1×2
150000 8
*In older versions of MATLAB, before R2016b, you would have to do something like this:
C = A./repmat(B,size(A,1),1);
size(C)
ans = 1×2
150000 8

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by