Matrix operations in three dimensions
Show older comments
I'm creating synthetic surfaces by summing multiple frequency components of random phase and orientation. Is there a faster way to do this? It seems that I could build the 3D components matrix without a loop, but I'm not sure how.
% Create domain
[X,Y] = meshgrid(0:.1:50,0:.1:50);
f = logspace(0,3,10);
theta = 90*rand(size(f));
A = f/1000;
% Build one surface for each frequency:
components = NaN(size(X,1),size(X,2),length(f));
for k = 1:length(f)
components(:,:,k) = A(k) * sin(f(k)*(X*sind(theta(k))+Y*cosd(theta(k))) + rand);
end
% Sum all components to create surface:
Z = sum(components,3);
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!