Vectorizing code ( calling a function with input as a matrix ) fails
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I have a function
if true
% function f=eu(c,theta, alpha, beta,P,D )
end
Then input c is a 1*2 matrix. Now I have C which is a 5051 *2 matrix. I would like to call function eu 5051 times and calculate its value for every row of C. I know I can write a loop for that but it is slow. So I want to do something called Vectorizing code. I tried this way.
if true
%
load D
load C
eu1=@(c)eu(c,1.1,0.2,0.1,[1/3.1/3/1/3],D )
u=eu1(C,theta, alpha, beta,P,D )
end
But the result u is still a scalar but not a 5051*1 vector as I expected it to be. Do you know where I am wrong?
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!