Copy variables into excel smoothly

20 次查看(过去 30 天)
I have a variable A:
24.3712410000000
24.2311330000000
23.4083360000000
24.2096500000000
23.6800080000000
23.2512100000000
23.5765810000000
24.1315920000000
23.4942910000000
24.3568280000000
I want to copy this into excel, however excel does not view these as numbers since comma in excel is "," not "."
So I wonder how I can work around this? I also want the values to have two decimals:
In excel it should look like this:
24,37
24,23
23,41
etc.
  2 个评论
Stephen23
Stephen23 2023-4-21
编辑:Stephen23 2023-4-21
"So I wonder how I can work around this?"
Don't copy-paste data into Excel. The simple, easy, robust approach is to use WRITEMATRIX:
C B
C B 2023-4-21
one way if he dont want to change locale and still need to do this then he can conver this to string or just add
'24,37
like this in this way excel dont apply formatting, please correct me if i am wrong

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2023-4-21
编辑:Stephen23 2023-4-21
"So I wonder how I can work around this?"
Don't copy-paste data into Excel. The simple, easy, robust approach is to use WRITEMATRIX:
If you really must copy-paste data then you will need to change the decimal radix character... you could either do this within Excel (e.g. paste as text, replace char, paste special) or within MATLAB, e.g.:
V = [24.371241;24.231133;23.408336;24.20965;23.680008;23.25121;23.576581;24.131592;23.494291;24.356828]
V = 10×1
24.3712 24.2311 23.4083 24.2096 23.6800 23.2512 23.5766 24.1316 23.4943 24.3568
C = strrep(compose('%#.8g',V),'.',',');
fprintf('%s\n',C{:})
24,371241 24,231133 23,408336 24,209650 23,680008 23,251210 23,576581 24,131592 23,494291 24,356828
"In excel it should look like this"
I recommend exporting the data at its full precision, and only changing the display precision in Excel.
Note that whether MS Excel displays numeric data with a decimal comma or a decimal point depends entirely on your locale settings. The locale settings make absolutely no difference to the numeric data stored in the Excel file.

更多回答(0 个)

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by