Determining mean and creating a bar chart in Matlab

12 ビュー (過去 30 日間)
Siddharth Satishchandran
Siddharth Satishchandran 2021 年 6 月 20 日
回答済み: KALYAN ACHARJYA 2021 年 6 月 21 日
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 Center および File ExchangeAnimation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by