Why won't my matlab function plot? Whenever I enter in a variable I no lines come up in my matlab figure.
Here's the code:
%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
Try this:
%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']);
You don't need a for to make a scatter plot, just plot without lines and a symbols ('o' in this case)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.