简体   繁体   English

其中一个图表没有在MATLAB中绘图

[英]One of the graphs is not plotting in MATLAB

I have three graphs to plot. 我有三张图可供绘图。 They all plot fine alone, but when I want the graphs plotted in separate windows, the second graph is not plotted. 它们都可以单独绘制,但是当我想要在单独的窗口中绘制图形时,不会绘制第二个图形。

This first graph plots fine: 第一张图很好:

function wave = carrier( t )
    %The carrier signal is a sine wave
    wave=sin(10*pi*t);
    %Plots the carrier wave
    figure(1);
    plot(wave);
    title('Figure 1: ASK Carrier signal')
    xlabel('Time')
    ylabel('Amplitude')
end

This is the second graph which does not plot: 这是第二张图,没有绘制:

% Generates the data signal then plots it. The data signal is: 10110100
function [ D ] = data( t )
    %Genereates the data signal
    D=[ones(1,100) zeros(1,100) ones(1,100) ones(1,100) zeros(1,100) ones(1,100) zeros(1,100) zeros(1,100)];
    %Plots the data signal
    figure(2);
    plot(t,D);
    title('Figure 2: Data signal')
    xlabel('Time')
    ylabel('Amplitude')
end

Finally, this is the third graph that plots: 最后,这是绘制的第三个图:

function [ modulated ] = ASK( t )
%Using '.*'to multiply the arrays element by element
    modulated=data(t).*carrier(t);
    figure(3);
    %plots both the ASK and the data signal on the same graph
    plot(t,modulated,t,data(t), 'LineWidth',2);
    title('Figure 3: ASK modulated wave')
    xlabel('Time')
    ylabel('Amplitude')
    legend('ASK (t)','data(t)')
%     for i=1:1:10;
%       %adding noise to simulate real life transmission of data
%         modulated(round(rand(1)*800))=rand(1);
%     end

end

How can I make all three graphs plot fine in separate windows? 如何在单独的窗口中将所有三个图形绘制得很好? This is what it looks like: http://prntscr.com/2i75xg BTW, already tried subplot, same thing. 这就是它的样子: http//prntscr.com/2i75xg BTW,已经尝试过子图,同样的事情。

The function data makes figure 2 the active figure. 功能data使图2成为活动数字。 You call data in the plot command in the function ASK which makes figure 2 active. 您可以在函数ASK中的plot命令中调用data ,这会使图2处于活动状态。 That's why nothing is displayed in figure 3. 这就是图3中没有显示任何内容的原因。

You probably want something like this in ASK : ASK你可能想要这样的东西:

d = data(t);
figure(3)
plot(t, modulated, t, d, 'LineWidth'2);

I was able to make the plots work for all 3 functions, but only if the input vector, t, has a length of exactly 800. This is because in the function data, you hardcode D to have a length of 800: 我能够使图表适用于所有3个函数,但前提是输入向量t的长度恰好为800.这是因为在函数数据中,硬编码D的长度为800:

D=[ones(1,100) zeros(1,100) ones(1,100) ones(1,100) zeros(1,100) ones(1,100) zeros(1,100) zeros(1,100)];

If you pass anything else in, you will receive an error that "vector lengths must match." 如果您传递任何其他内容,您将收到“矢量长度必须匹配”的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM