How can I put names one by one using char()?

1 view (last 30 days)
경환 고
경환 고 on 18 Nov 2021
Answered: Image Analyst on 18 Nov 2021
Is there any way to receive student names on the keyboard one by one and generate a matrix about the names I recieved?
When recieving student names, char() needs to be used.
  1 Comment
Rik on 18 Nov 2021
Your question is not clear to me. However, based on your user name, you should note Matlab stores characters in UTF-16, so not every character is just a single char scalar.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 18 Nov 2021
Try this:
titleBar = 'Enter a name';
dialogBoxWidth = 100;
caUserInput = {'a'}
loopCounter = 1;
maxIterations = 1000;
listOfNames = cell(maxIterations, 1); % Allocate more than enough. We'll crop it down later.
while ~isempty(caUserInput) && loopCounter < maxIterations
% Ask user for one name.
defaultValue = 'Myself';
userPrompt = sprintf('Enter name #%d (click Cancel to exit) :', loopCounter);
caUserInput = inputdlg(userPrompt, titleBar, [1, dialogBoxWidth], {num2str(defaultValue)});
% Bail otu if they clicked Cancel.
if isempty(caUserInput)
% Assign the user's response to our master call array.
listOfNames{loopCounter} = caUserInput{1};
loopCounter = loopCounter + 1;
listOfNames = listOfNames(1:loopCounter - 1)




Community Treasure Hunt

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

Start Hunting!

Translated by