Effacer les filtres
Effacer les filtres

Fill an empty table with input from different variables

5 vues (au cours des 30 derniers jours)
Erik Näslund
Erik Näslund le 23 Mai 2023
Commenté : Erik Näslund le 24 Mai 2023
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!

Réponse acceptée

Sufiyan
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)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by