필터 지우기
필터 지우기

2D Surface with periodic structure.

조회 수: 4 (최근 30일)
Michael
Michael 2017년 8월 16일
답변: John BG 2017년 8월 17일
Hello
Below is a section of code that I am working on. The basic idea is to create a surface 30mm square that has a surface that varies according to two sinewave functions. However, my code runs into issue in the Z assignment of the loop. Any help would be appreciated. Also if you have a more compact way
LengthX = 30; % X Length of sample in mm
LengthY = 30; % Y Length of sample in mm
X_k =2; % Number of Periods along X
Y_k =1; % Number of Periods along Y
DegX = pi .* X_k; %Degrees in X
DegY = pi .* Y_k; %Degrees in y
StepSize = 0.05; % Evenly Spaced X,Y gridpoints
x=0:StepSize:LengthX; y= 0:StepSize:LengthY;
NumXStep = DegX / length(x);
NumYStep = DegY / length(y);
Z = zeros(length(x), length(y));
for Counter = 0:1:length(x)
for Counter2 = 0:1:length(y)
% Z =(sin(x)+sin(y)),(-2*pi:0.1:2*pi),(-2*pi:0.1:2*pi);
Z[Counter, Counter2] = sin(NumXStep*Counter)+sin(NumYStep*Counter)
end
end
surf(x,y,Z)

채택된 답변

John BG
John BG 2017년 8월 17일
Hi Michael
1.
LengthX = .03; % X Length of sample in mm
LengthY = .03; % Y Length of sample in mm
X_k =2; % Number of Periods along X
Y_k =1; % Number of Periods along Y
2.
Don't need DegX DegY
% DegX = 2*pi*X_k; % Degrees in X
% DegY = 2*pi*Y_k; % Degrees in y
3.
The frequencies are needed, but you haven't defined them
T1=.01 % 10mm
T2=.02 % 20mm
f1=1/T1
f2=1/T2
4.
Reduce the step to avoid poor resolution
StepSize = 0.0005; % Evenly Spaced X,Y gridpoints
x=[0:StepSize:LengthX];
y= [0:StepSize:LengthY];
% don't need for loop either
[X,Y]=meshgrid(x,y)
Z=sin(2*pi*f1*X)+sin(2*pi*f2*Y)
.
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance
John BG

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 8월 16일
In MATLAB, [] is never used for indexing, only for list construction.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by