How to request an input

조회 수: 5 (최근 30일)
Antony
Antony 2011년 12월 18일
If I want the user to type in a 3x3 matrix of his/her choice before the program, what command will I use?

채택된 답변

Walter Roberson
Walter Roberson 2011년 12월 18일
If it is before the program, you would not have any control over what the user used :-)
Perhaps you are thinking of input() or inputdlg()
  댓글 수: 3
Antony
Antony 2011년 12월 18일
Or simply if I say, create a program that takes any 3x3 matrix as input.
Walter Roberson
Walter Roberson 2011년 12월 18일
It is complicated and usually unproductive to program in such a way that it is not possible for the user to enter anything other than a 3 x 3 matrix. It is usually much simpler and faster to check to see whether what the user entered was indeed a 3 x 3 matrix and to reject it otherwise, perhaps looping back and asking again.
If you want to create a 3 x 3 array of locations in which to enter values, you can create 9 uicontrol('Style','edit') whose Position are set to show up as you want; or you could use a uitable() with Data set to cell(3,3)

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

추가 답변 (1개)

Image Analyst
Image Analyst 2011년 12월 18일
Or you can get fancy and use a table like the example in the help:
f = figure('Position',[200 200 400 150]);
fprintf('Here is what we are loading into the table:\n');
dat = rand(3)
cnames = {'X-Data','Y-Data','Z-Data'};
rnames = {'First','Second','Third'};
hTable = uitable('Parent',f,'Data',dat,'ColumnName',cnames,...
'RowName',rnames,'Position',[20 20 360 100]);
% Get data back out
data = get(hTable, 'Data')

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by