Fill an empty table with input from different variables

조회 수: 6 (최근 30일)
Erik Näslund
Erik Näslund 2023년 5월 23일
댓글: Erik Näslund 2023년 5월 24일
Hello,
I have a table that needs to be concatenated, with a new table (T_nm) I'm trying to create. The table should have rows equal to the length of the vector ("obs") and have two columns with the variable names "subject" and "prov", respectively.
The column, "subject", should be filled with, the input corresponding to the variable, "n" and the "prov"-column filled with "m". These variables will change for different tables, but always be in the form of text/character.
I have created an empty table;
T_nm = table('Size', [numel(obs) 2], 'VariableTypes', ["string", "string"], 'VariableNames', {'subject', 'prov'})
However, I'm not successfull filling the column rows with "n" and "m", respectively.
Any advice is much appreciated!

채택된 답변

Sufiyan
Sufiyan 2023년 5월 24일
You can use the repmat as shown in the code below.
% Define the variables
n = 'value of n';
m = 'value of m';
% Replace with your own vector
obs = [1, 2, 3];
% Create a new table
T_nm = table(repmat({n}, length(obs), 1), repmat({m}, length(obs), 1), 'VariableNames', {'subject', 'prov'});
You can go through the link given below to understand more about “repmat.
Hope this helps!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by