필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by