2015-10-09 62 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')