Matlab Cody——Basics Rounding 题解

1. Problem 42641. MATLAB Basic: rounding

错误写法:

1
2
3
function y = round_zero(x)
y = round(x,TieBreaker="tozero");
end

正确写法:

1
2
3
function y = round_zero(x)
y = fix(x);
end

2. Problem 42642. MATLAB Basic: rounding II

1
2
3
function y = round_x(x)
y = round(x);
end

3. Problem 42643. MATLAB Basic: rounding III

1
2
3
function y = round_x(x)
y = floor(x);
end

4. Problem 42644. MATLAB Basic: rounding IV

1
2
3
function y = round_x(x)
y = ceil(x);
end

5. Problem 2559. Check that number is whole number

1
2
3
function y = your_fcn_name(x)
y = (x==round(x));
end

6. Problem 2866. Matlab Basics - Rounding II

1
2
3
function y = round_3_d_p(x)
y = round(x,3);
end

7. Problem 2867. Matlab Basics - Rounding III

1
2
3
function y = round_ten_thou(x)
y = round(x,-4);
end

8. Problem 2120. Rounding off numbers to n decimals

1
2
3
function y = myround(x,n)
y = round(x,n);
end

9. Problem 43278. Make roundn function

1
2
3
function y = myroundn(x,n)
y = round(x,n-1);
end

10. Problem 713. Find the maximum number of decimal places in a set of numbers

题目意思:给定一个向量或值矩阵,计算输入中的最大小数位数。尾随零不算有效。没有有效数字将导致答案为 0。
题解:没有找到一个优雅的写法,所有先放空。

1

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2022-2024 CPY
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信