How do I create a table and add a row of text from an existing matrix?
17 ビュー (過去 30 日間)
古いコメントを表示
I have a large 7000 x 125 matrix. The matrix was created from doing a 'readcell' operation to pull data from excel. I have since manipulated that data within matlab to a point where I can't go back and just do 'readtable' instead. Therefore, I want to create an exportable table that has the heading for each of the columns. I am willing to type out the heading for each column 125 times, but I am open to ideas on how to pull just the column headings from excel and attach them to the new table in Matlab. I would provide some code but it would just be a readfile and the matrix so feel free to generate any examples with a smaller matrix if necessary. I can provide some code if needed however.
2 件のコメント
the cyclist
2023 年 2 月 3 日
It would actually be better if you uploaded a few rows (including) header of the original Excel file, for testing solutions. There is enough variation in how things are stored, that can make for surprisingly different methods to doing the data manipulation.
Is the matrix you have stored in MATLAB just a double-precision numeric array, or some other data type?
回答 (2 件)
Sulaymon Eshkabilov
2023 年 2 月 3 日
Here is one of the possible solutions with strcat() to rename the table header variable names, e.g.:
DAT = randi(13, 15);
RR = array2table(DAT) % Table header var. names are: DAT1, DAT2, DAT3 ... DAT15
for ii = 1:length(DAT)
OLD{ii} = strcat('DAT', num2str(ii));
NEW{ii}=strcat('X', num2str(ii));
end
RR = renamevars(RR, OLD, NEW) % Renamed by new variable names: X1, X2, X3, ... X15
0 件のコメント
the cyclist
2023 年 2 月 3 日
% Pull the data as a table (even though we are only going to use it to get the header row)
tbl = readtable("TestFile.xlsx");
% Here is your processed data, which is now a numeric
M = rand(7,3);
% Put the numeric data into a table, with the headers
tableM = array2table(M,'VariableName',tbl.Properties.VariableNames)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Database Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!