Fill an empty table with input from different variables

7 views (last 30 days)
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!

Accepted Answer

Sufiyan
Sufiyan on 24 May 2023
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!

More Answers (0)

Tags

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!