Need help creating a matrix based on user inputs for the following snake like pattern
1 回表示 (過去 30 日間)
古いコメントを表示
Need help creating a matrix of X and Y coordinates for each point (1,2,3,N,etc). shown in the pattern below:
Ideally the pattern would be defined by a set of user inputs: 1. User defines the x spacing (1 to 2, 3 to 4, etc.) 2. User defines the y spacing (2 to 3, 4 to 5, etc.) 3. The number of total coordinates (x,y) for each point below will be determined by a user defined grid size (NxN). Only 8 points were shown here as an example. 4. I envision a [X] Nx1 matrix, and a [Y] Nx1 matrix where when plotted would produce the pattern shown below.
I'm a complete Matlab newb. I needs some guidance on how to get started.
Thanks
0 件のコメント
回答 (1 件)
Geoff Hayes
2014 年 10 月 20 日
Since the grid size is NxN, then wouldn't your X and Y vectors have N*N elements or coordinates each, one for each square in the grid? In your first example, your grid is a 4x4 matrix. What would the x coordinate be for each element in the grid? If we start at the bottom left and assume that this is 1, then
X = [1 2 3 4 4 3 2 1 ...];
where we move along the first (bottom) row from left to right, and assign an x-coordinate for each square. When we do the second row, we just move backwards, starting at the far right (4) and move to the left (1). We can continue in that pattern for each of the four rows.
With the Y coordinates, we do something similar. If we start at the bottom left and assume that this is 1, then
Y = [1 1 1 1 2 2 2 2 ...]
where we move along the first (bottom) row from left to right, and assign a y-coordinate for each square. Since y corresponds to row, all y values in each row are identical. When we move to the second row, the y coordinates just jump by one.
You can then plot the data as
plot(X,Y)
and see the different patterns.
5 件のコメント
Geoff Hayes
2014 年 10 月 21 日
How do you plan on getting the user to input the data? Through a text file of coordinates, GUI, prompts at the Command Line? And when you do have he data/pattern what do you plan on doing worth it?
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!