MATLAB Answers


trapz whe x is a matrix

Jose Costa さんによって質問されました 2019 年 11 月 19 日 15:56
最新アクティビティ dpb
さんによって コメントされました 2019 年 11 月 22 日 18:48
さんの 回答が採用されました
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.

  0 件のコメント

サインイン to comment.





1 件の回答

Answer by dpb
on 19 Nov 2019 at 23:32
 Accepted Answer

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.
for i=1:N

  3 件のコメント

Jose Costa 2019 年 11 月 22 日 14:31
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 2019 年 11 月 22 日 14:32
sorry, 2500x11.
2019 年 11 月 22 日 18:48
MATLAB is not Octave! Converse is also true... :)
Feel free to submit the enhancement request...I'd suggest referencing this thread if do so.

サインイン to comment.

Translated by