Need help creating a matrix based on user inputs for the following snake like pattern

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

Réponses (1)

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

Sudo's answer moved here
I probably confused my original post by including the 4 grid pattern samples. The samples were meant to show the pattern only.
To clarify, I'm looking to have an X,Y coordinate for each of the 2 points that create the line before the pattern changes direction.
For example on point 1. I'll have an X,Y coordinate say 0,0. The point 2 will have an X + some user defined distance for the X coordinate and Y will remain the same. Now for the third point Y will either increase or decrease, depending on pattern direction, by some user defined spacing.
Does that help clear things up?
Thanks for the reply!
So using the above definitions for X and Y, they can be "shortened" to
X = [1 4 4 1 ...]
Y = [1 1 2 2 ...]
where the first two points are (1,1) and (4,1) with the "user defined distance" in the x-direction of 3. The third point increases in y to give us (4,2), with the fourth point being (1,2) where the user-defined distance in the x-direction is negative 3.
Any suggestions on how to get this into matlab? Now that I have at least one other person understanding my problem I'm ready for some help direction on setting this up in matlab so that I can create these profiles automatically.
Thanks!
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?
sudo
sudo le 21 Oct 2014
Modifié(e) : sudo le 21 Oct 2014
I plan to prompt the user to input (gui) preferably but command line is sufficient : 1. X spacing, 2. Y spacing 3. Size of Grid (nxn) 4. Rotation of pattern about the middle in degrees. The output will be a csv that contains the data/pattern in X,Y coordinates in column 1,2 with N rows. The file will be used to position a x-motor, y-motor.

Connectez-vous pour commenter.

Produits

Question posée :

le 19 Oct 2014

Modifié(e) :

le 21 Oct 2014

Community Treasure Hunt

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

Start Hunting!

Translated by