フィルターのクリア

Fill an empty table with input from different variables

5 ビュー (過去 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!
  1 件のコメント
Erik Näslund
Erik Näslund 2023 年 5 月 24 日
Thank you! It worked perfect.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by