User's input as Table-Row
1 view (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
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'};
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!