User's input as Table-Row

1 view (last 30 days)
Lefteris K
Lefteris K on 5 Apr 2020
Answered: Florian Floh on 5 Apr 2020
I have a specific question:
There is a program,which asks from the user to enter a number as an answer into a question. Later, I want this answer(a number from 3 to 10),
to be the number of rows in a table. Although I can fix simple rows,columns and name them, I cannot find a way, to develop a code
which will select the number-input of the user, as number of the rows(for example if he picks 5, I want the program to create a 5-row array)
I cannot make a pre-ordered array because I don't know what the user is going to select.
How I can ask from MATLAB to give me,as many rows, as the number that will be picked
by the user?

Answers (1)

Florian Floh
Florian Floh on 5 Apr 2020
Here is my suggestion on how to approach this problem:
% Here is your user input
userInput = 3;
% create an array containing zeros (or uses ones if it should contain 1s)
% that has one column
yourArray = zeros(userInput,1);
% Convert your array to a table
T = array2table(yourArray);
% Rename the column, if desired
T.Properties.VariableNames = {'NameOfColumn'};

Tags

Community Treasure Hunt

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

Start Hunting!