vertcat errors - need a 'workaround' solution

4 visualizaciones (últimos 30 días)
Douglas Leaffer
Douglas Leaffer el 15 de Jun. de 2023
Movida: Stephen23 el 15 de Jun. de 2023
Please suggest a 'workaround' or alternate solution for the following error (code and data tables attached)
"An error occurred when concatenating the table variable 'ImpactWind' using VERTCAT. Caused by: Error using categorical/vertcat Ordinal arrays must have the same categories, including their order."
Note: categories are: 'other', 'airport', 'road', 'railway', 'bus-sta' ... and the common categories to both tables to vertcat are: 'other', 'airport', 'road'
load 'datatables.mat'; % note: two tables will load, C1 and R1, both have 'ImpactWind' as a variable column
X = vertcat(C1, R1)
Error using tabular/vertcat
An error occurred when concatenating the table variable 'ImpactWind' using VERTCAT.

Caused by:
Error using categorical/vertcat
Ordinal arrays must have the same categories, including their order.

Respuesta aceptada

Stephen23
Stephen23 el 15 de Jun. de 2023
S = load('datatables.mat')
S = struct with fields:
C1: [3420×21 table] R1: [1025×21 table]
T1 = S.C1;
T2 = S.R1;
C1 = categories(T1.ImpactWind)
C1 = 4×1 cell array
{'other' } {'railway'} {'airport'} {'road' }
C2 = categories(T2.ImpactWind)
C2 = 4×1 cell array
{'other' } {'airport'} {'road' } {'bus-sta'}
C0 = unique([C1;C2],'stable')
C0 = 5×1 cell array
{'other' } {'railway'} {'airport'} {'road' } {'bus-sta'}
T1.ImpactWind = setcats(T1.ImpactWind,C0);
T2.ImpactWind = setcats(T2.ImpactWind,C0);
T0 = [T1;T2]
T0 = 4445×21 table
LAeq VLFN LFN MFN HFN Day Season DayNumber Wkend RushHR Site Temp Hum WS ImpactWind Deg Bar WS_HI RF UFPConc lnUFP _____ ______ ______ ______ ______ _____ ______ _________ _____ ______ _____ ______ ___ __ __________ ____ ______ _____ _____ _______ ______ 55.7 80.959 71.176 56.284 55.629 true false 6 false false false 9.1111 27 21 railway 45 1032 true false 11850 9.3801 54.55 86.04 72.115 56.148 54.21 true false 6 false false false 9.5 25 23 railway 67.5 1032 true false 13050 9.4765 56.5 87.401 74.502 59.194 55.401 true false 6 false false false 9.5 25 23 railway 67.5 1032 true false 9390 9.1474 56.25 88.284 77.218 58.492 55.271 true false 6 false false false 9.5 25 23 railway 67.5 1032 true false 7740 8.9542 61.55 96.355 81.347 62.264 59.521 true false 6 false false false 9.5 25 23 railway 67.5 1032 true false 5780 8.6622 56.8 88.414 77.233 59.283 54.997 true false 6 false false false 9.5 25 23 railway 67.5 1032 true false 5895 8.6819 55.6 84.186 74.424 58.529 54.151 true false 6 false false false 9.2222 24 25 railway 67.5 1031.9 true false 5570 8.6252 53.2 77.159 71.649 55.711 52.469 true false 6 false false false 9.2222 24 25 railway 67.5 1031.9 true false 5480 8.6089 53.5 81.756 72.694 56.928 52.419 true false 6 false false false 9.2222 24 25 railway 67.5 1031.9 true false 4730 8.4617 56 93.19 79.098 58.817 54.379 true false 6 false false false 9.2222 24 25 railway 67.5 1031.9 true false 4030 8.3015 57.25 93.925 80.813 58.982 55.997 true false 6 false false false 9.2222 24 25 railway 67.5 1031.9 true false 4640 8.4425 54.95 84.922 71.069 59.342 53.42 true false 6 false false false 9.1667 24 26 other 22.5 1031.9 true false 4705 8.4564 56 88.818 73.952 59.295 54.738 true false 6 false false false 9.1667 24 26 other 22.5 1031.9 true false 4725 8.4606 55.05 87.831 72.037 58.687 53.735 true false 6 false false false 9.1667 24 26 other 22.5 1031.9 true false 5020 8.5212 53.4 80.796 68.165 55.232 53.331 true false 6 false false false 9.1667 24 26 other 22.5 1031.9 true false 7685 8.947 54.05 82.048 72.777 57.595 53.227 true false 6 false false false 9.1667 24 26 other 22.5 1031.9 true false 5685 8.6456
  1 comentario
Douglas Leaffer
Douglas Leaffer el 15 de Jun. de 2023
Movida: Stephen23 el 15 de Jun. de 2023
Thanks Stephen, worked perfectly !

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by