# How to add two sets of imported data?

5 visualizaciones (últimos 30 días)
Ashley Bhugwandin el 7 de Dic. de 2021
Respondida: Siddharth Bhutiya el 30 de Mzo. de 2023
Hi
I am currently working on a program that requires me to add two sets of data that is imported in tables. However whenever I run the code, I get this error message:
Operator '+' is not supported for operands of type 'table'.
Error in MastersDraft_1 (line 3)
How do I fix it?
##### 4 comentariosMostrar 2 comentarios más antiguosOcultar 2 comentarios más antiguos
Ashley Bhugwandin el 8 de Dic. de 2021
How would I add the respective columns?
Thanks
Peter Perkins el 10 de Dic. de 2021

Iniciar sesión para comentar.

### Respuestas (2)

Siddharth Bhutiya el 30 de Mzo. de 2023
Starting R2023a, tables now directly support arithmetic operations like plus, minus, sum, etc. So this kind of work becomes very easy. You can directly add two tables or numeric values to a table.
T1 = table([1;3],[2;4]);
T2 = table([1;2],[3;4]);
T = T1 + 10
T = 2×2 table
Var1 Var2 ____ ____ 11 12 13 14
T = T1 + T2
T = 2×2 table
Var1 Var2 ____ ____ 2 5 5 8
You can find more information about what things are now supported here: Direct Calculations on Tables and Timetables
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Peter Perkins el 7 de Dic. de 2021
Ashley, there's a long example in the doc that talks about "how to perform calculations by using the numeric and categorical data that the table contains" at length:
t.X = t.X + 1
or
tplus1 = varfun(@(x)x+1,t)
or perhaps
t{:,["X" "Y" "Z"]) = t{:,["X" "Y" "Z"]) + 1
or
t.Variables = t.Variables + 1
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Tables en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by