Error when combine tables vertically under some circumstances

8 vues (au cours des 30 derniers jours)
Jinyang Du
Jinyang Du le 8 Juin 2021
Commenté : Jinyang Du le 8 Juin 2021
I have two sets of data, up_data and upt_data. They have the same variable names. But when I try to use [up_data; upt_data] to combine them, error pops out as following:
An error occurred when concatenating the table variable 'posture' using VERTCAT.
Caused by:
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Here is a test to show that the variable names are the same.
However, when I write them into csv files and then read them back as follows:
writetable(up_data, 'up_data.csv');
writetable(upt_data, 'upt_data.csv');
up_data = readtable('up_data.csv');
upt_data = readtable('upt_data.csv');
upright_alldata = [up_data ; upt_data];
It works perfectly well. I wonder what went wrong. I attached the csv files as well for your references.
  5 commentaires
Scott MacKenzie
Scott MacKenzie le 8 Juin 2021
Modifié(e) : Scott MacKenzie le 8 Juin 2021
I suggest you provide an example minimal set of MATLAB statements that generates the error you are seeing. Furthermore, to make things easier for someone trying to help you, it's best to do this by embedding the code directly in your question or comment
Jinyang Du
Jinyang Du le 8 Juin 2021
Thank you for your kind suggestions. I will post them in the question.

Connectez-vous pour commenter.

Réponse acceptée

Cris LaPierre
Cris LaPierre le 8 Juin 2021
Modifié(e) : Cris LaPierre le 8 Juin 2021
I've edited your post to run your data and display the underlying issue.
You use char arrays to create posture. To combine char arrays, they must have the same number of characters. However, in one table you use 'upright' and in the other you use 'upright_t'.
The simplest fix is to use strings instead.
pos_up = table(repmat("upright", size(up_data, 1), 1));
pos_upt = table(repmat("upright_t", size(upt_data, 1), 1));
  1 commentaire
Jinyang Du
Jinyang Du le 8 Juin 2021
Thank you so much for your kind help! Have a nice day :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by