Change amount of significant figures or precision in array elements

35 Ansichten (letzte 30 Tage)
Is there a way to do this?
Example: In LabVIEW there is a thing called width and if you specify a width of 5 for some number, the maximum number of digits it can have will be 5. Is this possible in MATLAB?
  1 Kommentar
Stephen23
Stephen23 am 2 Okt. 2018
Bearbeitet: Stephen23 am 2 Okt. 2018
"Is there a way to do this?"
Of course: change the class of the array (numeric, vpa, custom...)
But generally there is no point to this: what is your use case?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 2 Okt. 2018
If you absolutely must do that, see the section in the round (link) function documentation on: Round Elements to Specified Number of Significant Digits (link).
That is likely not your best option. I would do the calculations with the data you have, and round the result to the requisite number of significant digits.
  17 Kommentare
PromoCodeBSJ
PromoCodeBSJ am 5 Okt. 2018
This is the response I got from Support:
Hello Eric,
Thank you for contacting MathWorks Technical Support Department. My name is Aaron and I am writing in reference to your Technical Support Case #03271769 regarding 'Formatting precision in MATLABTable'.
I understand that you would like to specify the precision displayed in a MATLAB Table when including the table in a generated report. Thank you for sharing the link to the MATLAB Answers forum page.
I have been in contact with the developers of MATLAB about this potential capability in the MATLAB Report Generator. Unfortunately, it is not currently possible to specify the precision of a table in the MATLAB Report Generator. The developers of MATLAB are currently considering implementing this feature in a future release of the program.
In the meantime, there are a couple of potential workarounds to consider:
1. Consider first rounding the entries of the table using the 'round' function and then converting the rounded numbers to strings. This will ensure that the table entries are displayed in the desired precision. For an example of how to do this, please refer to the attached file named 'TablePrecisionRound.m' and the comments in the file.
For more information about the 'round' function, please refer to the following link:
https://www.mathworks.com/help/matlab/ref/round.html
2. Consider using the 'compose' function with a specified number format in order to convert the numbers to string arrays. By using the 'compose' function, a custom precision or number format can be easily specified. As an example of how to do this in MATLAB, please refer to the attached file named 'TablePrecisionCompose.m' and the comments in the file.
For more information about the 'compose' function, please refer to the following link:
https://www.mathworks.com/help/matlab/ref/compose.html
Please note that I certainly understand that each of the workarounds above are not ideal. You can be assured that the developers are considering implementing the feature in a future release.
For now, I will tentatively close this case from an administrative perspective. However, please let me know if there are any additional related questions as I would be happy to re-open the case and assist.
Sincerely,
Aaron Zakrzewski MathWorks Technical Support Department
Star Strider
Star Strider am 5 Okt. 2018
Thank you for posting that.
I’m relieved to know that the formatting capability doesn’t exist, and that I didn’t miss something.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by