Concatenate a string array and a table of different dimensions
Afficher commentaires plus anciens
I have a txt which that has two parts (see the txt attached): an non-editable header (in the file attached, everyline that has a # as first charater), followed by a tab-delimited table. To replace some of the values in the table, I have imported the table in matlab by doing the following:
table = readtable('data.txt');
The command above will skip the header section of the file and import the table as expected. I then replaced the values.
Problem: What I need to do now, is to paste the table below the header section of the original file and save it as a txt file. This part is essential for the file to be properly read in the package I'm using to run my analyses. This is where I got stuck and can't seem to find a way out. It seems to me that the header can only be imported in MATLAB as a string array by doing the following:
header = readlines('data.txt');
header = header(1:24, :);
So, I have been trying to turn the table into a string array, so it could be pasted below header. On the one hand, if I try to do that:
tableArray = table2array(table);
The tableArray object has more dimensions (= columns) that the header object, so they can't be concatenated. On the other hand, if I try to reduce the dimensions of tableArray, the columns of the tables are merged together, which will make it impossible to use the file for later analyses.
I am not a Matlab expert and I've run out of options. I would really appreciate some help -- even a suggestion -- with this.
Thank you in advance!
Réponse acceptée
Plus de réponses (1)
I'd probably store that information in the Description property of the table.
T = array2table(magic(4));
T.Properties.Description = "A table array created from the magic(4) matrix";
This information is not displayed when the table is displayed normally, but it can be seen using the summary function.
disp(T)
summary(T)
s = T.Properties.Description
1 commentaire
Roberto Petrosino
le 9 Mar 2021
Modifié(e) : Roberto Petrosino
le 9 Mar 2021
Catégories
En savoir plus sur Text Data Preparation dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!