matlab - Rounding up to the nearest tenth
问题描述
I am trying to round up the cx_n
to its nearest number if the cx_n
value doesn't match with yt
. With the code below, I can round up but it goes all the way to 1. For example,
one of the cx_n
values is 0.58, I want to round up 0.6, not 1.0. How can I accomplish this?
This is my MATLAB Code:
Fn = 3; %Nyquist Frequency
Fnr = 6; %Nyquist Rate
Fs = Fnr*5; %Sampling frequency
Ts = 1 / Fs; %Sampling period
T = 1 / 3;
N = T / Ts; %Number of samples per period
start = 0;
stop =N-1;
c_increment = 1;
c_n = start:c_increment:stop;
c_nTs = c_n*Ts;
cx_n = sin(2*pi*3*c_nTs);
for m_d = 1:length(cx_n)
for quantisation = 1:length(yt)
if (m_d ~= quantisation )
p = round(cx_n);
stem(c_nTs, p);
end
end
end
解决方案
just replace p = round(cx_n);
with p = round(cx_n,1);
See MATLAB documentation: round
Y = round(X,N) rounds to N digits:
- N > 0: round to N digits to the right of the decimal point.
- N = 0: round to the nearest integer.
- N < 0: round to N digits to the left of the decimal point.
推荐阅读
- php - 如果数据通过 rasberrypie 以 urlencode 格式发布,我们如何打印个人数据
- javascript - 可以从 React-Router 的 HashRouter 历史记录中删除路由吗?
- android - 约束布局 0dp 不适用于 Android 视图绑定
- javascript - 护照认证或JWT认证。哪一个更好?
- windows - 在循环中计算 hh:mm:ss
- javascript - 不调用 forkJoin 中的日志行
- ios - Xcode 11.4 不允许使用实例变量
- sublimetext3 - 如何在 sublime text 3 上禁用突出显示?
- r - 有没有一种简单的方法来比较列表中数据框的匹配元素并替换到数据框中?
- asp.net-core - .NET Core 3.1 的 Azure DevOps 代码覆盖率