is possible Array + Array but element by element without using loop ?
이전 댓글 표시
Dear colleagues
I want to know if there is a command that allow to add array with another array but without using a loop, I want something like this .* but adding.
here i write an example:
X= [1 2 3]; Y=[4 5 6];
Z= X.+Y Z = [(1+4) (1+5) (1+6) (2+4) (2+5) (2+6) (3+4) (3+5) (3+6)]
Z = [5 6 7 6 7 8 7 8 9]
thank you for your help
댓글 수: 3
Ashmil Mohammed
2015년 7월 10일
I dont know if there is a function , But does your situation restrict you from using loops?
Jorge Peñaloza Giraldo
2015년 7월 10일
Star Strider
2015년 7월 10일
My code is as fast as MATLAB can be to do the calculations you want. Large vectors will take longer with any code, but bsxfun is the fastest function for what you want to do.
If you want to do comparisons on the run times between various ways to do the calculations, use the timeit function.
채택된 답변
추가 답변 (1개)
Jorge Peñaloza Giraldo
2015년 7월 10일
0 개 추천
댓글 수: 1
Star Strider
2015년 7월 10일
My pleasure! ¡El gusto is mío!
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!