Given 2 vectors X,Y both of length N, How do I act on every single term in X with every single term in Y into a N by N matrix?
조회 수: 2 (최근 30일)
이전 댓글 표시
Just to make myself clear, assuming X = [1 2 3], Y = [1 2 3] and that I want to act with 'exp'
I want to create a matrix Z = [exp(1+1) exp(1+2) exp(1+3) ; exp(2+10 exp(2+2) exp(2+3) ; exp(3+1) exp(3+2) exp(3+3)]
I know I can run a simple for loop, but How do I make it simple using matlab matrix/vectors notation? Thanks
댓글 수: 0
채택된 답변
Stephen23
2016년 5월 30일
편집: Stephen23
2016년 5월 30일
>> X = [1,2,3]; Y = [1,2,3];
>> exp(bsxfun(@plus,X.',Y))
ans =
7.3891 20.0855 54.5982
20.0855 54.5982 148.4132
54.5982 148.4132 403.4288
Or
>> [Xm,Ym] = ndgrid(X,Y);
>> exp(Xm+Ym)
ans =
7.3891 20.0855 54.5982
20.0855 54.5982 148.4132
54.5982 148.4132 403.4288
댓글 수: 0
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 802.11n/ac (Wi-Fi 4 and Wi-Fi 5)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!