Add column to several tables in a function
1 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(1 个)
Rishabh Singh
2022-2-9
Hi,
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!