inputdlg question

4 ビュー (過去 30 日間)
Eugene
Eugene 2012 年 2 月 18 日
Is it possible to output the string contents of a variable to a prompt or dialog title for inputdlg? I would also like to seed the first position of the created cell with the person's name.
It would look something akin to:
-------------------------------------
quanShoppers = 3;
namesList = {'Sally', 'Fred', 'John'};
for n=1:quanShoppers
prompt = {'Enter item for' namesList(n), 'Enter price paid'};
dlg_title = 'Shopping list for' namesList(n);
groceryList = {namesList(n),inputdlg(prompt, dlg_title, 1)};
end
------------------------------------
For the first iteration, the expected outputs will look like:
Shopping list for Sally
Enter item for Sally
Enter price paid

採用された回答

Image Analyst
Image Analyst 2012 年 2 月 18 日
Try this:
namesList = {'Sally', 'Fred', 'John'};
groceryList = cell(length(namesList), 2);
for n=1:quanShoppers
line1 = sprintf('Enter item for %s', namesList{n})
line2 = 'Enter price paid'
prompt = {line1; line2}
dlg_title = sprintf('Shopping list for %s', namesList{n})
userResponse = inputdlg(prompt, dlg_title, 1)
groceryList(n, 1) = namesList(n);
groceryList{n, 2} = userResponse{1};
groceryList{n, 3} = userResponse{2};
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFinancial Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by