User's input as Table-Row

1 回表示 (過去 30 日間)
Lefteris K
Lefteris K 2020 年 4 月 5 日
回答済み: Florian Floh 2020 年 4 月 5 日
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?

回答 (1 件)

Florian Floh
Florian Floh 2020 年 4 月 5 日
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'};

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by