Add column to several tables in a function

3 ビュー (過去 30 日間)
Vlatko Milic
Vlatko Milic 2022 年 1 月 5 日
回答済み: Rishabh Singh 2022 年 2 月 9 日
Hi,
I have three tables titled "Table 1, Table 2 and Table 3". Each table consists of 9 columns and approximately 10,000 rows. I want to create a new column in each table (based on the division of two columns) while maintaining the table names (and also variable names) after processing. Each column in the tables is today defined as 10000x1 double.
My initial idea is to create a function where I am performing this task, see below:
C = {Table1,Table2,Table3}
%%
for k = 1:numel(C)
[Output(C,:)] = my_calc(C{k});
end
However, I get the error "A table row subscript must be a numeric array containing real positive integers, a logical array, a character vector, a string array, or a cell array of character vectors." Is this because of the use of doubles?(see comment above)
Thank you in advance!

回答 (1 件)

Rishabh Singh
Rishabh Singh 2022 年 2 月 9 日
Hi,
It seems you want to concatenate a table. Refer to following example for better understanding.
LastName = ["Sanchez";"Johnson";"Zhang";"Diaz";"Brown"];
Age = [38;43;38;40;49];
Smoker = [true;false;true;false;true];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
patients = table(LastName,Age,Smoker,Height,Weight) % table size is 5x5 table
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];
patients = [patients table(BloodPressure)] % adding a column, converting the table to 5x6 size.
Hope this helps.

カテゴリ

Help Center および File ExchangeTables についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by