How to integrate a vector over a surface of x,y-coordinate vectors
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have 3 vectors. One x vector with x-coordinates, one y vector with y-coordinates and a vector z with values to this x,y-coordinates. Now I need to integrate the values of the z vecotor over the x,y-surface.
I tried to first make a 2D-Mesh with
[X,Y] = meshgrid(x,y)
and then resape the vector z on to this mesh with
Z = griddata(x, y, z, X(:,1), Y(1,:));
this didnt work.
Can anyone tell me what I am doing wrong or can tell me how I can integrate one verctor over the x,y-coordinates of vector x and y ?
I am using matlab R2022b
Thank you in advance :)
3 commentaires
Réponse acceptée
KSSV
le 19 Juil 2023
Modifié(e) : KSSV
le 19 Juil 2023
You need to find out whether your data is structured is unstructured. Depedning on that, you need to proceed.
%%structured
xi = unique(x) ; yi = unique(y) ;
[X,Y] = meshgrid(xi,yi) ;
Z = reshape(z,size(X)) ;
figure
surf(X,Y,Z)
%%unstructured
m = 100 ; n = 100 ;
xi = linspace(min(x),max(x),m) ;
yi = linspace(min(y),max(y),n) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
figure
surf(X,Y,Z)
To integrate have have look on trapz
4 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!