필터 지우기
필터 지우기

Divide each column by a constant from a vector

조회 수: 17 (최근 30일)
Frederik Bjerregaard
Frederik Bjerregaard 2022년 3월 5일
댓글: Frederik Bjerregaard 2022년 3월 5일
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?

채택된 답변

Voss
Voss 2022년 3월 5일
편집: Voss 2022년 3월 5일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by