2015-10-09 64 views
-3

爲什麼我的matlab函數不能繪圖?每當我輸入一個變量時,我的matlab圖中都沒有出現任何線條。需要幫助:Matlab函數繪圖

下面的代碼:


%we have decided to emulate an auditory sensor 

function GroupSensorFun1(N) %user chooses # of variables 

    %creating sensor data for time and decibles 

    timeVec = 1:1:N; %vector emulates N seconds 

    soundVec = 1000/rand(N,1) %randomly generates N readings 

    hold on 

    for i = 1:N %loop N times to plot all data 

     %plot data on to scatter graph one varible at a time. 

     %scatter(timeVec(i),soundVec(i)) 

     plot(timeVec(i),soundVec(i)) 

    end 

    % Create xlabel 

    xlabel({'Time in Seconds'}); 

    % Create ylabel 

    ylabel({'Decibles scaled'}); 

    % Create title 

    title({'Auditory Sensor Data in ', num2str(N) ' Seconds'}); 

    hold off 
+2

你真的需要for循環嗎?我的意思是你不能簡單地使用'plot(timeVec,soundVec)'? –

+0

請勿使用雙倍空間碼。這很難閱讀。 –

+0

如果沒有一組可重現的數據,我們如何判斷您是否試圖繪製NaN或Infs? –

回答

1

試試這個:

%we have decided to emulate an auditory sensor 

function GroupSensorFun1(N) %user chooses # of variables 

    %creating sensor data for time and decibles 

    timeVec = 1:1:N; %vector emulates N seconds 

    soundVec = 1000/rand(N,1) %randomly generates N readings 

    %scatter(timeVec,soundVec) 

    plot(timeVec,soundVec,'o') 

    % Create xlabel 

    xlabel('Time in Seconds'); 

    % Create ylabel 

    ylabel('Decibles scaled'); 

    % Create title 

    title(['Auditory Sensor Data in ' num2str(N) ' Seconds']); 

你不需要爲使散點圖,只是情節沒有線條和符號(」 o')