How can I add " " to first row and column in a cell

2 Ansichten (letzte 30 Tage)
Orongo
Orongo am 14 Okt. 2018
Kommentiert: Orongo am 15 Okt. 2018
Hi, I have created a cell with average values of 100 simulations. Now I need to save this as a text file (space delimited or tab delimited) and append a first row dating each column 1996 to 2014 and append a column starting from 0 to 10. So the final file should look something like this
\begin{table}[]
\begin{tabular}{llllllllllllllllllll}
& "1996 & "1997 & "1998 & "1999 & "2000 & "2001 & "2002 & "2003 & "2004 & "2005 & "2006 & "2007 & "2008 & "2009 & "2010 & "2011 & "2012 & "2013 & "2014 \\
"0" & 50787.83 & 47436.17 & 46186.5 & 45683.67 & 46057.83 & 47013.17 & 48264.5 & 50231.5 & 51607.67 & 52102.5 & 53428.67 & 55074.83 & 55994.67 & 57143.67 & 58627 & 58441.5 & 57857.17 & 58500 & 59133.33 \\
"1" & 55247.83 & 50901.5 & 47571.67 & 46402.5 & 45965.5 & 46415.33 & 47408.67 & 48660.17 & 50574.5 & 51968.33 & 52603.17 & 53985.67 & 55702.67 & 56674.83 & 57777.5 & 59281.83 & 59128.83 & 58549.5 & 59263.67 \\
"2" & 58692.67 & 55244.67 & 50939.17 & 47694 & 46577.5 & 46207.17 & 46678.67 & 47649.67 & 48880.83 & 50775.33 & 52282.83 & 53033 & 54464.17 & 56212.83 & 57121.5 & 58207.17 & 59760.67 & 59717.5 & 59264.17 \\
"3" & 61737.83 & 58658.67 & 55259.67 & 51039.17 & 47897.5 & 46825.33 & 46469.67 & 46934.67 & 47869.67 & 49071.17 & 51068.5 & 52712.33 & 53502.67 & 54924.33 & 56576.83 & 57456.5 & 58620.17 & 60264.83 & 60328.33 \\
"4" & 64110 & 61690.83 & 58689.17 & 55348.83 & 51187.17 & 48127.17 & 47110.67 & 46742 & 47157.83 & 48042 & 49339.67 & 51444.67 & 53143.67 & 53971.17 & 55296 & 56903.17 & 57830 & 59098.33 & 60867 \\
"5" & 64941.67 & 64102.67 & 61705.83 & 58748.67 & 55470.33 & 51380.67 & 48350.83 & 47363.33 & 46974.17 & 47331 & 48271 & 49657.83 & 51813.33 & 53539.67 & 54313.67 & 55584 & 57231.33 & 58336.83 & 59693.5 \\
"6" & 63331.17 & 64964.67 & 64169.5 & 61790.83 & 58867.33 & 55665 & 51623.83 & 48565.17 & 47548.83 & 47146.33 & 47645.33 & 48727.33 & 50083.5 & 52207.67 & 53870.83 & 54582.17 & 55910.67 & 57733.5 & 58983.83 \\
"7" & 60858.5 & 63407.5 & 65060.67 & 64272.17 & 61933 & 59037.17 & 55857 & 51833 & 48756.33 & 47696.5 & 47368.83 & 47987 & 49111.83 & 50500.5 & 52593.5 & 54191.67 & 54927 & 56437.17 & 58374.83 \\
"8" & 58079.17 & 60920.17 & 63499.5 & 65189.17 & 64434 & 62126.83 & 59266.17 & 56080.67 & 52033.67 & 48955.5 & 47989.5 & 47762.33 & 48411.33 & 49530.17 & 50818.33 & 52839 & 54503.83 & 55453.67 & 57084.67 \\
"9" & 55710.67 & 58150 & 61031.33 & 63629 & 65354.67 & 64640.83 & 62343 & 59489.83 & 56297.5 & 52182.33 & 49200.33 & 48376.17 & 48182.17 & 48848.83 & 49914.5 & 51152.5 & 53205 & 55058.17 & 56106.83 \\
"10" & 54632.33 & 55824.67 & 58302.17 & 61172.17 & 63780.67 & 65538.17 & 64849 & 62576.83 & 59712 & 56481.33 & 52457.83 & 49606.5 & 48782.67 & 48564.83 & 49177.5 & 50207.5 & 51494 & 53744.83 & 55719.67
\end{tabular}
\end{table}
How can I write this in Matlab?
  3 Kommentare
Guillaume
Guillaume am 14 Okt. 2018
Bearbeitet: Guillaume am 14 Okt. 2018
This appears to be latex syntax. It's going to depend on what packages are loaded, but usually the " symbol is a right-double quotation mark. On the left it should be `` (two reversed sinqle quotes). However, I don't see the need for quotes at all.
If the first row is a header, shouldn't there be a \hline after it? Similarly, if the first column is a header, wouldn't you have a | after the first l in the {tabular} column description?
Orongo
Orongo am 14 Okt. 2018
Hi Walter, yes there should be a double quote at end of the year number. This was a mistake.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Guillaume
Guillaume am 14 Okt. 2018
Adding the headers to your cell array as you require is trivial:
newcellarray = [{}, compose('"%d', 1996:2014); compose('"%d", (1:10)'), yourcellarray]
  5 Kommentare
Guillaume
Guillaume am 15 Okt. 2018
There is no point of putting your mean matrix into a 1x1 cell array. It just adds an unnecessary level of indirection, so:
avg_m_male = mean(cat(3, m_xt_sim_male{:}), 3);
With the 2nd option, I don't know why I wrote 1:10 instead of 0:100. Also, I forgot a ' in the 2nd compose. And I made a mistake with creating the top-left cell:
%with avg_m_male being a 101x19 matrix:
out_cell = [{[]}, compose('"%d', 1996:2014); compose('"%d"', (0:100)'), num2cell(avg_m_male)];
Orongo
Orongo am 15 Okt. 2018
Thank you for clarifying. I did modify you initial suggestion but it's not as clean as yours! Many thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by