make the double data to be with n digit decimal data
% It is necessary when you plot the value as a text box or print it
Taesam Lee (2021). decimal(X,ndecimal,is_round) (https://www.mathworks.com/matlabcentral/fileexchange/57107-decimal-x-ndecimal-is_round), MATLAB Central File Exchange. Retrieved .
This is somehow a rite-of-passage for MATLAB learners. Does everyone write one of these? There are certainly plenty of FEX already.
This is a reasonable submission: neat and tidy with a clear description.
A few tips:
* Do not put an empty line before the "Examples". Instead you should put one single '%' sign to make that line a comment. You will see why when you call "help decimal".
* The function name "decimal" is a bit too broad: this function does _rounding_, so the name should perhaps reflect that.
* The input argument |is_round| is used incorrectly to select the |floor| operation.
* The explanation that this function is "necessary" when printing values is not true: the standard |fprintf| is quite good at rounding to decimal places:
>> fprintf('%.*f\n', 1, 20/3)
>> fprintf('%.*f\n', 3, 20/3)
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!