I have a Y matrix size 2500x11 were each line corresponds to the 11 vales of curve points for trapezoidal integration.
the x values are not uniform and they vary so i have a second matrix for X size 2500x11.
I' tring to integrate using trapz (X,Y,2) but I get error "X must be a vector.".
How ca one use trapz with a matrix for x values? In octave it works.

 채택된 답변

dpb
dpb 2019년 11월 19일

0 개 추천

TMW only implemented variable X spacing for the full array, not by column (or row). Have to loop to do it...worthy of an enhancement request for the added functionality it would seem.
N=size(Y,1);
for i=1:N
Q(i)=trapz(X(:,i),Y(:,i));
end

댓글 수: 3

Jose Costa
Jose Costa 2019년 11월 22일
Thanks, But loops are always very slow. Prefere in this case to explicitly code the trapezoidal method and use matricial calculation.
In the 50x11 example, loop time was 0.0456 and matrix time was 8.6840e^-4
An enhancement would be good. In Octave it exists.
Jose Costa
Jose Costa 2019년 11월 22일
sorry, 2500x11.
dpb
dpb 2019년 11월 22일
MATLAB is not Octave! Converse is also true... :)
Feel free to submit the enhancement request...I'd suggest referencing this thread if do so.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품

릴리스

R2019b

태그

질문:

2019년 11월 19일

댓글:

dpb
2019년 11월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by