Add column to several tables in a function

조회 수: 1 (최근 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 CenterFile Exchange에서 Tables에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by