matlab - 如果语句中的 X=0 的值未在 matlab 图中绘制
问题描述
试图从二进制输入中绘制询问、fsk 和 psk 调制的图表。psk 和 fsk 调制图还可以,但 ask 调制图似乎忽略了 0 值并且没有绘制它们。
尝试使用 ask=sin(0); 问=楼梯(0);并反转 if else 语句
prompt = 'Enter bit stream ';
ff = 'Enter space frequency, f = ';
ff2 = 'Enter mark frequency, f2 = ';
x=input(prompt)
f=input(ff)
f2=input(ff2)
nx=size(x,2);
for i=1:1:nx
t = i:0.01:i+1;
if x(i)==1
ask=sin(2*pi*f*t);
fsk=sin(2*pi*f2*t);
psk=sin(2*pi*f*t);
else
ask=0;
fsk=sin(2*pi*f*t);
psk=sin(2*pi*f*t+pi);
end
subplot(4,1,1);
stairs([x,x(end)]);
hold on;
grid on;
ylabel('Amplitude')
xlabel('Time')
title('Binary Input')
axis([1 nx+3 -2 2]);
subplot(4,1,2);
plot(t,ask);
hold on;
grid on;
ylabel('Amplitude')
xlabel('Time')
title('ASK Modulation')
axis([1 nx+3 -2 2]);
subplot(4,1,3);
plot(t,fsk);
hold on;
grid on;
ylabel('Amplitude')
xlabel('Time')
title('FSK Modulation')
axis([1 nx+3 -2 2]);
subplot(4,1,4);
plot(t,psk);
hold on;
grid on;
ylabel('Amplitude')
xlabel('Time')
title('PSK Modulation')
axis([1 nx+3 -2 2]);
end
解决方案
每当在 matlab 中绘图时,您的数据需要具有相同的长度。在您的情况下,您试图在整个 t 向量上绘制一个 0 以进行询问。您需要将其更改为零向量,如下所示:
prompt = 'Enter bit stream ';
ff = 'Enter space frequency, f = ';
ff2 = 'Enter mark frequency, f2 = ';
x=input(prompt)
f=input(ff)
f2=input(ff2)
nx=size(x,2);
for i=1:1:nx
t = i:0.01:i+1;
if x(i)==1
ask=sin(2*pi*f*t);
fsk=sin(2*pi*f2*t);
psk=sin(2*pi*f*t);
else
ask=zeros(length(t), 1);
fsk=sin(2*pi*f*t);
psk=sin(2*pi*f*t+pi);
end
subplot(4,1,1);
stairs([x,x(end)]);
hold on;
grid on;
ylabel('Amplitude')
xlabel('Time')
title('Binary Input')
axis([1 nx+3 -2 2]);
subplot(4,1,2);
plot(t,ask);
hold on;
grid on;
ylabel('Amplitude')
xlabel('Time')
title('ASK Modulation')
axis([1 nx+3 -2 2]);
subplot(4,1,3);
plot(t,fsk);
hold on;
grid on;
ylabel('Amplitude')
xlabel('Time')
title('FSK Modulation')
axis([1 nx+3 -2 2]);
subplot(4,1,4);
plot(t,psk);
hold on;
grid on;
ylabel('Amplitude')
xlabel('Time')
title('PSK Modulation')
axis([1 nx+3 -2 2]);
end
现在你得到这样的东西:
推荐阅读
- elasticsearch - 弹性搜索结果不如预期
- javascript - react native:在选择器周围添加框架以使其看起来不错的方法是什么?
- html - 滚动条被隐藏,页面内容未完全显示
- kotlin - 计算二维数组的总和
- delphi - 你能检查一下是否调用了 Exit()
- python - 如何检查 decimal.is_nan() 数组中的所有值?
- ejabberd - 无法安装任何 ejabberd contrib 模块
- firebase-mlkit - 如何使用 Firebase / ML Kit 识别和计数对象
- r - 使用 predict() 函数绘制 CI 区间时出现问题
- angular - Angular 9 - NGRX 如何注册“全局”减速器