How can I graph this matrix?
1 回表示 (過去 30 日間)
古いコメントを表示
theta=zeros(N,N);
theta = mod(bsxfun(@plus, (1:N), (1:N).'),2);
x1=(R*cos(theta+Phase)/sqrt(2));
y1=(R*sin(theta+Phase)/sqrt(2));
plot(x1,y1);
fill(x1,y1,color1);
hold;
How can I graph the matrix "theta"? This is the x and y I should use but for some reason it just gives me a slanted line. In this case, N, R, and color1 are inputed by the user and the phase is pi/4. Thank you!
回答 (1 件)
Nick Counts
2016 年 11 月 20 日
As KSSV said, we need to know what you mean by "graph the matrix."
Your code will definitely make a line, though. From the documentation for plot()
plot(X,Y) plots vector Y versus vector X. If X or Y is a matrix,
then the vector is plotted versus the rows or columns of the matrix,
whichever line up. If X is a scalar and Y is a vector, disconnected
line objects are created and plotted as discrete points vertically at
X.
Since you passed two matrixes, plot goes element by element (I believe down each column, successively).
Now, look at what kind of x1 and y1 you are creating. They are simply alternating between two values.
>> y1=(sin(theta)/sqrt(2))
y1 =
0 0.5950 0 0.5950 0
0.5950 0 0.5950 0 0.5950
0 0.5950 0 0.5950 0
0.5950 0 0.5950 0 0.5950
0 0.5950 0 0.5950 0
That means when plot() works its way through the matrixes, it is plotting like this:
>> [x1(1:10)', y1(1:10)']
ans =
0.7071 0
0.3821 0.5950
0.7071 0
0.3821 0.5950
0.7071 0
0.3821 0.5950
0.7071 0
0.3821 0.5950
0.7071 0
0.3821 0.5950
So plot() is just drawing a line back and forth between those two points over and over :)
3 件のコメント
Nick Counts
2016 年 11 月 20 日
So what do your x1, y1, and theta values correspond to?
You will probably need need to establish the coordinates of each square. Currently, x1 and y1 are not doing that :)
Nick Counts
2016 年 11 月 20 日
Something like this?
theta = mod(bsxfun(@plus, (1:5), (1:5).'),2)
pcolor(theta)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!