필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
sudo
sudo 2014년 10월 19일
편집: sudo 2014년 10월 21일
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

답변 (1개)

Geoff Hayes
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
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?
sudo
sudo 2014년 10월 21일
편집: sudo 2014년 10월 21일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by