Copy variables into excel smoothly

20 Ansichten (letzte 30 Tage)
Joel
Joel am 21 Apr. 2023
Bearbeitet: Stephen23 am 21 Apr. 2023
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 Kommentare
Stephen23
Stephen23 am 21 Apr. 2023
Bearbeitet: Stephen23 am 21 Apr. 2023
"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 am 21 Apr. 2023
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 21 Apr. 2023
Bearbeitet: Stephen23 am 21 Apr. 2023
"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.

Weitere Antworten (0)

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by