2014-01-10 4 views
0

플롯 할 세 개의 그래프가 있습니다. 그들은 모두 잘 음모를 꾸미지 만 그래프를 별도의 창에 표시하려면 두 번째 그래프가 플롯되지 않습니다. 미세그래프 중 하나가 MATLAB에서 플롯하지 않습니다

이 제 그래프는 :

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 

이 플롯되지 않는 두번째 그래프이다 : 마지막

% 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 

을,이 제 그래프하다 플롯 :

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 

세 개의 그래프를 모두 별도의 창에 잘 표시하려면 어떻게합니까? 이것은 다음과 같습니다. http://prntscr.com/2i75xg BTW, 이미 시도한 subplot, 같은 것.

답변

1

기능 data은 그림 2를 활성 숫자로 만듭니다. 그림 2를 활성화시키는 ASK 함수의 plot 명령에서 data으로 전화하십시오. 아무것도 그림에 표시되지 않는 이유는 3

당신은 아마 ASK이 같은 뭔가를 원하는이다 :

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

그림 3에서 그래프를 플로팅하는 방법뿐만 아니라 데이터를 플로팅하는 방법은 무엇입니까? – Hamoudy

+0

내 편집을 참조하십시오. 또는 계산 및 플롯에 대해 별도의 함수를 만듭니다. – Molly

+0

고마워요! – Hamoudy

1

나는 플롯 3 개 기능을 작동 할 수 있었다,하지만 경우에만 입력 벡터, t 당신이 무엇을 전달하면

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)]; 

, 당신이 "벡터 길이가해야 오류가 발생합니다 : 함수 데이터에, 당신은 (800)의 길이를 가지고 D를 하드 때문에이 정확히 800의 길이 시합."

+0

Molly는 올바르게 작동합니다. ASK 기능의 "figure (3)"다음에 데이터 호출을 포착하지 않았습니다. – Sam

+0

예는 t = 0 : 0.01 : 7.99; – Hamoudy

관련 문제