NxN Matrix with sinusoidal element values

I would like to create an N x N matrix with its entries to have values in a shape of a sinus curve when ploted. E.g.: let's take an arbitrary number for the first entry value of the first row. The second value is increased and so on, until the values drop again to a minimum, from which entry on they go up again and so on and so forth...until the N-th entry is reached. This is for the rows. For the column entries I would like to have the same. How can this be achieved?

 채택된 답변

Star Strider
Star Strider 2015년 4월 30일

0 개 추천

I am not certain what you want. This takes the sin function on the x and y values separately:
x = linspace(0, 4*pi);
[X,Y] = meshgrid(x);
Z = sin(X) + sin(Y);
figure(1)
surf(X, Y, Z)
grid on

추가 답변 (1개)

Joseph Cheng
Joseph Cheng 2015년 4월 29일
편집: Joseph Cheng 2015년 4월 29일

2 개 추천

well you'd just plot row 1 like you would a sinusoid.
x = [1:100];
y = sin(2*pi*x/6);
then repeat row 1 to make it NxN or in my example 100x100
NxN = repmat(y,100,1);
to make first entry random just choose random starting number for x

댓글 수: 4

Lucius
Lucius 2015년 4월 30일
But in this way the matrix will look like stripes, won't it? What I intended was to have a sinus curve in row, as well as in column. So the matrix would look like mountains and valleys regularly located all over the matrix.
Then i misread your last statement. then just create a meshplot and perform a 3d surface sine wave.
x = [1:100];
[x y] = meshgrid(x,x);
z = sin(2*pi*x/30).*sin(2*pi*y/30);
surf(z)
Lucius
Lucius 2015년 4월 30일
I would accept this answer, too, if only the accept button was visible here. Thank you very much!
Star Strider
Star Strider 2015년 4월 30일
@Lucius — I voted for it, so Joseph gets the same number of points.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Linear Algebra에 대해 자세히 알아보기

제품

질문:

2015년 4월 29일

댓글:

2015년 4월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by