Get a user to input corordinates to form a matrix.

21 ビュー (過去 30 日間)
Giuseppe
Giuseppe 2014 年 3 月 23 日
コメント済み: Azzi Abdelmalek 2014 年 3 月 24 日
Hi I have the matrix;
points = [2 5; 6 9; 7 8; 9 10; 6 10]
I want to make it that the user inputs the points and a subsequent matrix is created. I think if I make a 2 x n matrix of zeros and get the user to input how many coordinates there is. But then I am stuck on how to ask the user to enter the coordinates. Could I use matrix manipulation with the input function to ask for the x and y values etc?
NOTE: These points are x and y coordinates i.e. 2 5 the x coordinate is 2 and the y coordinate is 5. I was also thinking maybe I could load a csv file and have the user specify the points in a table. I would prefer the aforementioned method if possible.
Thanks,

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 3 月 23 日
編集済み: Azzi Abdelmalek 2014 年 3 月 23 日
You can try this
x=input('enter x coordinates between square bracket, like [1 2 3] ')
y=input('enter y coordinates between square bracket, like [1 2 3] ')
You can also use inpudlg
n=10; % number of lines
a= inputdlg('enter x coordinates','test',n)
x=str2num(a{1})
b= inputdlg('enter y coordinates','test',n)
y=str2num(a{1})
  1 件のコメント
Giuseppe
Giuseppe 2014 年 3 月 24 日
I like the idea of inpudlg. Thanks.

サインインしてコメントする。

その他の回答 (1 件)

Mischa Kim
Mischa Kim 2014 年 3 月 23 日
Enter x- and y- coordinates, values separated by an empty space:
prompt = {'x-coor:','y-coor:'};
name = 'Input coordinates';
numlines = 1;
answer = inputdlg(prompt,name,numlines)
points = [str2num(answer{1}); str2num(answer{2})]';
  2 件のコメント
Giuseppe
Giuseppe 2014 年 3 月 24 日
I prefer the layout of this dialogue. How could I use that layout with this code so that there is only one dialogue?
n=10; % number of lines
a= inputdlg('enter x coordinates','test',n)
x=str2num(a{1})
b= inputdlg('enter y coordinates','test',n)
y=str2num(a{1})
Thanks.
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 3 月 24 日
n=3; % number of lines
ab= inputdlg('enter x and y coordinates','test',n)
xy=str2num(ab{1})

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by