Fill an empty table with input from different variables
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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!
0 commentaires
Réponse acceptée
Sufiyan
le 24 Mai 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!
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!