Efficient implementation of a functions with vector arguments
조회 수: 1 (최근 30일)
이전 댓글 표시
I am an inexperienced MATLAB user. I need to define functions with an efficient implementation because they will be called many times. The function arguments are 3-D vectors, and the functions need access to individual elements of the vectors. The following is a toy example.
function y = foo( vector )
y = vector(1)*cos(vector(2))/(1+vector(3));
end
--------------------------
Then I could do
v = [2,pi/3,2];
foo(v)
ans = 0.3333
Is there a more efficient way to implement the above function?
Thanks, Ted Ersek
댓글 수: 1
Sean de Wolski
2013년 4월 3일
What does your real vector look like and what would you expect for the output?
채택된 답변
Doug Hull
2013년 4월 3일
편집: Doug Hull
2013년 4월 3일
Do not worry about efficiency until you know it is a problem. I think you might be surprised where the bottlenecks in your code are. First write clear, correct, maintainable code. When it is found to be slow, then you can optimize for speed. You will likely find that the maintainable code is faster than you need.
I would be VERY surprised if this code was the slowdown in any realistic code.
Doug
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!