Determining mean and creating a bar chart in Matlab

12 次查看(过去 30 天)
Hi I have a script that I have written to solve a problem for an assignment. I was wondering if I could get help on this? I have to write a Matlab script that calculates the mean call rate for animal IDs 1, 2, and 3 (ignore 0) for the entire session (e.g. no. of vocalizations/minute). For session duration, I can use the last value of the "AudioStopTime" column. I have to provide: (1) My script (2) A bar chart showing the call rate for each animal I have written the code for the mean call rate and created a bar chart but I just want to make sure I have answered the problem correctly or if there is a more simpler way of answering the problem. I have included the sample data here as well.
%% Mean Call Rate for each animal
% Clear data and figures
clc
clear
close all
% Load data
load(LabelTable.mat)
% Extract data
% ID 1
Animal_ID_1 = T(T.Caller_ID==1,:);
% ID 2
Animal_ID_2 = T(T.Caller_ID==2,:);
% ID 3
Animal_ID_3 = T(T.Caller_ID==3,:);
% Mean Call Rate
% mean call rate for ID 1
mn1 = mean(Animal_ID_1.AudioStopTime-Animal_ID_1.AudioStartTime);
% mean call rate for ID 2
mn2 = mean(Animal_ID_2.AudioStopTime-Animal_ID_2.AudioStartTime);
% mean call rate for ID 3
mn3 = mean(Animal_ID_3.AudioStopTime-Animal_ID_3.AudioStartTime);
% Plot bar chart
bar(categorical({'ID 1','ID 2','ID 3'}),[mn1 mn2 mn3])
xlabel(Animal ID''s')
ylabel('Mean Call Rate')
title('Mean Call Rate for Animal IDs’)

回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2021-6-21
load LabelTable.mat
% Extract data
% ID 1
Animal_ID_1 = T(T.Caller_ID==1,:);
% ID 2
Animal_ID_2 = T(T.Caller_ID==2,:);
% ID 3
Animal_ID_3 = T(T.Caller_ID==3,:);
% Mean Call Rate
% mean call rate for ID 1
mn1 = mean(Animal_ID_1.AudioStopTime-Animal_ID_1.AudioStartTime);
% mean call rate for ID 2
mn2 = mean(Animal_ID_2.AudioStopTime-Animal_ID_2.AudioStartTime);
% mean call rate for ID 3
mn3 = mean(Animal_ID_3.AudioStopTime-Animal_ID_3.AudioStartTime);
% Plot bar chart
bar(categorical({'ID 1','ID 2','ID 3'}),[mn1 mn2 mn3])
xlabel('Animal ID');
ylabel('Mean Call Rate');
title('Mean Call Rate for Animal IDs');

类别

Help CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by