Issues filling rounded numbers into MS Word
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello Matlab community!
A baffling one for me here, which should be relatively simple but is not turning out to be.
I'm using report generator to populate a number of Holes in a MS word template with variable values. One is a number containing many sf which I am using the 'round' command to truncate to 1 sf as below
roundedvalue = round(value,1);
append(D, roundedvalue);
However, when I run the script the variable is entered into MS Word still as a 10+sf value:
I guess my questions are:
- Is this a Matlab issue or an MS Word issue (I really hope it's a Matlab issue as I don't want to have to drag our my VB knowledge to script it...)
- If it is a Matlab issue, how can it be fixed?
Answers gratefully recieved!
0 comentarios
Respuestas (1)
Prateekshya
el 20 de Ag. de 2024
The issue you're experiencing is likely due to the way MATLAB handles numeric formatting when appending values to a Word document using the Report Generator. The 'round' function in MATLAB rounds the value to the specified number of decimal places, but when you append this value to a Word document, the default formatting might not reflect the desired precision.
To control the number of significant figures or decimal places when exporting to Word, you can convert the number to a string with the desired format before appending it. Here is a sample code for the same:
% Example value
value = 123.456789;
% Round the value to 1 decimal place
roundedValue = round(value, 1);
% Convert the rounded value to a string with 1 decimal place
formattedValue = sprintf('%.1f', roundedValue);
% Do further processing
For more information on 'sprintf', please refer to the below link: https://www.mathworks.com/help/matlab/ref/sprintf.html
I hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Waveform Generation 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!