Hi! I take an answer 3 minutes ago. With the answer i can take values for my array Phone. Now i want to add this script to GUI. in the gui there is just one push button it is goin to be "add phone number". so How i can add this script to gui ?
n = 2
for ii = 1:n
Phone(ii).name = input('Enter the name: ', 's');
Phone(ii).number = input('Enter the phone number: ','s');
Phone(ii).address = input('Enter the address: ','s');
end

 採用された回答

Image Analyst
Image Analyst 2012 年 5 月 25 日

0 投票

n = 2;
dlg_title = 'Input for personal data';
num_lines = 1;
for k = 1:n
prompt1 = sprintf('Enter name #%d', k);
prompt2 = sprintf('Enter phone number #%d', k);
prompt3 = sprintf('Enter address #%d', k);
prompt = {prompt1, prompt2, prompt3};
answer = inputdlg(prompt,dlg_title,num_lines);
Phone(k).name = answer{1};
Phone(k).number = answer{2};
Phone(k).address = answer{3};
end

その他の回答 (4 件)

Matt Kindig
Matt Kindig 2012 年 5 月 24 日

0 投票

To clarify, you are trying to make a GUI? Are you going to replace the calls to 'input' (which gets information from the command prompt) with text fields in the GUI (where you can type in the relevant information directly? If so, you should start with GUIDE, which will help you layout the GUI. There are a few examples in the startup for GUIDE to do things similar to your task.
At the command prompt, simply type
guide

3 件のコメント

Özgür Karagülle
Özgür Karagülle 2012 年 5 月 24 日
hi, yes i am trying to make gui for my script. my script is just down. I want to combine this script to my gui ? **** i know it is very easy for you but english of matlab help is heavy, i couldn't, can you help me ? I just want to make simple phone directory , in this gui there is just push buttons which are "Add Phone Number" and "Show All Numbers" ??
thank you..
Özgür Karagülle
Özgür Karagülle 2012 年 5 月 24 日
n = 2
for ii = 1:n
Phone(ii).name = input('Enter the name: ', 's');
Phone(ii).number = input('Enter the phone number: ','s');
Phone(ii).address = input('Enter the address: ','s');
end
Walter Roberson
Walter Roberson 2012 年 5 月 24 日
vals = inputdlg('Phone book', 'name', 'number', 'address');
Phone(ii).name = vals{1};
...

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

Özgür Karagülle
Özgür Karagülle 2012 年 5 月 24 日

0 投票

where i must paste this code?

1 件のコメント

Walter Roberson
Walter Roberson 2012 年 5 月 24 日
n = 2
for ii = 1:n
vals = inputdlg('Phone book', 'name', 'number', 'address');
Phone(ii).name = vals{1};
Phone(ii).number = vals{2};
Phone(ii).address = vals{3};
end

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

Özgür Karagülle
Özgür Karagülle 2012 年 5 月 24 日

0 投票

please help me, i have not enough english for matlab help doc. Matlab is international, isn't it ?

3 件のコメント

Walter Roberson
Walter Roberson 2012 年 5 月 24 日
Most of the MATLAB Answers volunteers are employed and can only answer in their spare time.
Oleg Komarov
Oleg Komarov 2012 年 5 月 24 日
@Özgür: please do not create additional answer but use comments or edit the original post.
I would suggest to avoid the GUI if you are new to MATLAB and interact with the user through the command line.
Özgür Karagülle
Özgür Karagülle 2012 年 5 月 24 日
ok. i am sorry , i didn't know :(

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

Özgür Karagülle
Özgür Karagülle 2012 年 5 月 24 日

0 投票

thank you for time Mr. Roberson, when i compile this codes it get an error = Error using inputdlg (line 109) NumLines size is incorrect.
Error in domain (line 3) vals = inputdlg('name', 'number', 'address');

4 件のコメント

Oleg Komarov
Oleg Komarov 2012 年 5 月 24 日
As you can see, now it's hard to understand which of Walter's comments this answer coprresponds to.
Özgür Karagülle
Özgür Karagülle 2012 年 5 月 24 日
this one =
n = 2
for ii = 1:n
vals = inputdlg('Phone book', 'name', 'number', 'address');
Phone(ii).name = vals{1};
Phone(ii).number = vals{2};
Phone(ii).address = vals{3};
end
Image Analyst
Image Analyst 2012 年 5 月 25 日
That's not the right way to use inputdlg() - see the help for the correct way.
Walter Roberson
Walter Roberson 2012 年 5 月 25 日
vals = inputdlg({ 'name', 'number', 'address'},'Phone Book');

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

カテゴリ

ヘルプ センター および File ExchangeMATLAB Mobile についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by