VGRID: utility to help vectorize code

版本 1.0.0.0 (2.3 KB) 作者: Sky Sartorius
VGRID helps vectorize code to handle n-d variables as inputs for e.g. trapz.
202.0 次下载
更新时间 2016/4/13

查看许可证

[siz,V,M,X1,X2,X3,...] = VGRID(v,x1,x2,x3,...) expands the inputs x1,x2,x3,... using meshgrid such that e.g. reshape(trapz(V,Xi),siz) is the same size as xi if xi is N-D. Use vgrid to help make your code more vectorized.

Input v is a vector. For each non-scalar xi, vgrid returns [Xi, M] = meshgrid(xi, v). Xi = xi for scalar xi.

Example: Numerically integrate the position of an object with various acceleration and starting velocity (without for loops).
time = 0:.1:3; % Seconds.
[v0,acceleration] = meshgrid(0:4,4:2:16); % Units: m/s and m/s^2.
[siz,timeVector,TimeGrid,V0,Acceleration] = VGRID(time,v0,acceleration);
velocity = V0 + Acceleration.*TimeGrid;
distance = trapz(timeVector,velocity);
distance = reshape(distance,siz);
surf(v0,acceleration,distance);

引用格式

Sky Sartorius (2026). VGRID: utility to help vectorize code (https://ww2.mathworks.cn/matlabcentral/fileexchange/56529-vgrid-utility-to-help-vectorize-code), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2016a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Calculus 的更多信息
版本 已发布 发行说明
1.0.0.0