需要帮助:Matlab函数绘图

时间:2015-10-09 01:07:31

标签: 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

1 个答案:

答案 0 :(得分: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')