Concatenate a string array and a table of different dimensions
Ältere Kommentare anzeigen
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!
Akzeptierte Antwort
Weitere Antworten (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 Kommentar
Roberto Petrosino
am 9 Mär. 2021
Bearbeitet: Roberto Petrosino
am 9 Mär. 2021
Kategorien
Mehr zu Tables finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!