table editing and excel export

6 次查看(过去 30 天)
Ceshi
Ceshi 2019-11-20
评论: dpb 2019-11-22
Hello,
I don't know Matlab well yet and can't get any further.
I get from an analysis of a Matlab program the results as a table, which I want to edit in Matlab and export to Excel.
Time Value1 Value2 ...
1.0 27832.2 129819.2 ....
... ...
After the first line, I would now like to insert 2 more lines. One line should contain the unit and the second line should contain a comment (2 of the test parameters).
In addition, a variable is to be added after each heading ( Value1 - Sample1, Value2 - Sample1...).
The table is then to be exported into an Excel table. The name should consist of the experiment data ( Sample1_date.xls). The two variables are read in at the beginning of the program.
Then a second Excel table is to be exported in which the data of the Value1-Value10 columns are converted with a conversion factor.
Can anyone help me?
Sorry for my bad english, I hope it's understandable.
  3 个评论
Ceshi
Ceshi 2019-11-22
编辑:dpb 2019-11-22
Okay so the export itself with writetable is no problem.
But I don't get it to insert 2 rows into my table.
My result table contains numbers and I want to insert a line with the units and a line with a comment in front of it.
e.g.
unit = {'kg' 'm' 's'..}
If I try like this:
concatenatedtable = [unit; resulttable];
I get the error message
Cannot concatenate the table variable 'xyz' because it is a cell in one table and
a non-cell in another.
dpb
dpb 2019-11-22
Ayup. No can do that. MATLAB table variables are like regular variables--they must be consistent in type. The only way you can write numeric data together with non is to use a cell array to hold the content. That then will probably make using your resulting table difficult unless this is solely for display purposes.
Tell/Show us what you're really trying to accomplish as an end result and probably be able to get some better approaches.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2019-11-22
I suggest you add the units in the column headers themselves, like
variableNames = {'Time_[sec]', 'Value1_Sample1_[kg]'};
  1 个评论
dpb
dpb 2019-11-22
There actually is a 'VariableUnits' property in the table object for exactly that purpose. As well as 'VariableDescriptions' and 'UserData' for additional identification.
It's unfortunate that the command window display of a table doesn't have a way to cause these to show up, though, you have to query their values (at least thru R2017b which is latest I've gotten around to installing here).

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by