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

2 views (last 30 days)
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

Answers (1)

Geoff Hayes
Geoff Hayes on 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 Comments
Geoff Hayes
Geoff Hayes on 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?
sudo
sudo on 21 Oct 2014
Edited: sudo on 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.

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!