point decimal to comma
35 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
how i can get my result in matlab editor with comma decimal ? i need just to see my result in command window with a comma :)
3 comentarios
dpb
el 22 de Abr. de 2020
Can't read the tiny images to tell what didn't work, but Rik's code works fine in the command window (or as code in function as edited and then executed).
>> n=pi;
>> strrep(sprintf('%.4f',n),'.',',')
ans =
'3,1416'
>>
But, as he says, there's no way I know of to change the behavior in MATLAB to use comma instead of decimal directly.
I thought that was what OS LOCALE settings were for and the idea is that applications were to be written to honor those settings/preferences and deal with transparently. BUT AFAIK, that ideal isn't in MATLAB (if it is in any large app of the ilk; I don't know; never had the opportunity to try/test it).
Respuestas (1)
Rik
el 22 de Abr. de 2020
So in summary: Matlab doesn't check the operating system's locale setting to determine the decimal separator. This question seems to suggest this behavior did actually happen in some situations, but it was (also?) a bug. There is even a doc page that suggests Mathworks will never change this behavior.
As a fallback you can convert a value to a char representation and use strrep on the result:
strrep(sprintf('%.4f',n),'.',',')
%or let Matlab determine an appropriate FormatSpec:
%strrep(num2str(n),'.',',')
The reason for these choices has probably to with code portability: now Matlab doesn't have to worry about the OS settings to interpret a plain text .m file. They could potentially allow it in live scripts, since those aren't plain text. I doubt you will convince them, so you might have to buy Mathworks or otherwise offer unreasonable amounts of money to have this implemented.
2 comentarios
dpb
el 23 de Abr. de 2020
Editada: dpb
el 23 de Abr. de 2020
The only concession TMW has made so far is the new(ish) readXXX routines... readmatrix and readvars are the two I can think of now that have name-value pairs of 'Decimal|ThousandsSeparator' to define the behavior for text files.
I'm sure it's a nightmare to try to support their code base that began before anybody in US cared there was such a thing as Europe as a potential market for software; what more try to adapt to them furriners' ways...
I'd be much more pleased if they would just bring complex variables up to full-fledged citizen status. For a scientific-oriented package with a Fortran start, would think 30 years would have been long enough.
Stephen23
el 23 de Abr. de 2020
Changing to a decimal comma would then require redefining the comma-separated list separator (otherwise how to interpret max(1,2) ?). If we follow MS Excel's lead the list separator could be the semi-colon, in which case the semi-colon for matrix construction also needs to be redefined.. .to what? There might be other required changes too... it certainly would not be a trivial change to the language.
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!