Need help creating a matrix based on user inputs for the following snake like pattern
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Geoff Hayes
le 20 Oct 2014
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 commentaires
Geoff Hayes
le 21 Oct 2014
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?
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!