Vectorisation of 2 2d matrix

조회 수: 3 (최근 30일)
Li zifan
Li zifan 2018년 8월 27일
편집: Stephen23 2018년 8월 27일
Hi, I want to answer of 2 arrays without using loops,
A=rand(100,100)
B=rand(8,1)
The out put C is going to be a 100*100*8 array, each layer is the difference between A and corresponding B row.
e.g. The second layer of C is gonna be A(:,:)-B(2,:).
Is there a way to manage this with out for loop?
Thanks

채택된 답변

Stephen23
Stephen23 2018년 8월 27일
편집: Stephen23 2018년 8월 27일
For MATLAB versions R2016b+:
C = A - reshape(B,1,1,[])
For earlier versions:
C = bsxfun(@minus,A,reshape(B,1,1,[]))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by