1

I have a table with dimensions 6x2. I have other table with dimensions 4x1, I tried to append the little table into the larger one but I couldn't do it because of the differences in dimensions. Do you have any suggestion to tackle this?

Code example:

id = {'AB';'ZX';'DF4';'CA';'AC';'FG'}
mean = [1.5;2;3;1.15;3.06;1]
table1 = table(id,mean);

id2 = {'ZZ';'ZB';'FG';'4FA'};
table2 = table(id2);
table2.Properties.VariableNames = {'id'};

I will then calculate the mean of the last 4 rows using an average of the first 6.

1 Answer 1

3

First of all and this is really important: dont call a variable "mean" as that is the average function in MATLAB.

i would recommend you to calculate them first and then concatenate the tables, but if you want it this way its possiible too. You just have to fill in something until you have the actual values

id = {'AB';'ZX';'DF4';'CA';'AC';'FG'};
mean_values = [1.5;2;3;1.15;3.06;1]; %way better than 'mean'
table1 = table(id,mean_values);

id2 = {'ZZ';'ZB';'FG';'4FA'};
table2 = table(id2);
table2.Properties.VariableNames = {'id'};
%add some sort of data like NaN 
table3=[table1;[table2 table(nan(height(table2),1),'Variablenames',{'mean_values'})]];

you could also use zeros or ones or any other number, but they maybe inflluence your calculation of the average(mean) while NaN does not:

mean([3 5 nan],'omitnan')

if you get an error while using mean saying 'Subscript indices must either be real positive integers or logicals.' you have to use

clear mean

or delete it manually from the workspace

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.