Create a new table based on variables of other tables (WITH DIFFERENT LENGTHS)
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
David E.S.
el 6 de Feb. de 2021
Comentada: Adam Danz
el 16 de Sept. de 2022
Hi! I want to create a new table based on variables of other tables; each variable has different length.
Supose I have a table (which name's "B"). I want to insert in another table the variables Type, Latitude, Longitude and Equtemp. I have another table which name is A and I want to take other variables of that table.
I'm trying to create a simple code but it gives me errors.
T = zeros(5, 14000); % T -> New table
T.Type = B.Type;
Unable to perform assignment because dot indexing is not supported for variables of this type.
Can you help me? Thanks!!
MATLAB Version: R2019b.
2 comentarios
José Jines
el 19 de Ag. de 2022
I have a table with 562000x4 so I just want column #3 from these data groups. How would I do it?
Adam Danz
el 16 de Sept. de 2022
Respuesta aceptada
Adam Danz
el 6 de Feb. de 2021
Editada: Adam Danz
el 6 de Feb. de 2021
T = zeros(5, 14000); % T -> New table
No, that's not a table. That's a matrix of 0s.
>I want to insert in another table the variables Type, Latitude, Longitude and Equtemp
If 1) the tables are the same height, 2) the variables listed above do not already exist in table A, and 3) you want to concatenate those variables to table A
A.Type = B.Type;
A.Latitude = B.Latitude;
% etc...
If the tables are not the same height you will need to pad the shorter table with some value (e.g. NaN) or horizontally concatenate them using outerjoin (see demo).
If the variable names already exist in table A you will need to use new variable names.
If you want to replace variables in table A with the variables in table B you would use the same syntax as above
A.Type = B.Type;
3 comentarios
Adam Danz
el 6 de Feb. de 2021
I know I just recommended padding which is a perfectly fine approach in some cases but on second thought, I suggest you use outerjoin.
Here's a demo: https://www.mathworks.com/matlabcentral/answers/634139-trying-to-pad-smaller-table-to-larger-table#answer_531979
If your table contains homogenous data (all numeric, all strings, etc), then padding may be easier and I could show you how after you give more info about your table (share a sample using head()). But if the table contains mixed classes, outerjoin is probably the better option.
Más respuestas (0)
Ver también
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!