How to code for Barchart and mean in matlab

1 view (last 30 days)
I am using Matlab for the first time. I have used R before but Im new to Matlab. The new lab Im in wants me to use more Matlab in place of R programming for the next project. Im working on primate vocalizations. We have data that we have collected over months for a number of individuals. Im tryin to create a script that calculates mean call rate for just the first three animals in the dataset (no. of vocalizations/minute) and i'm trying to create a bar chart showing the call rate of each animal. It would be great If I could get some help so I can get started on working with the larger datasets for the lab. I have attched the the extracted dataset that I am using as a sample to make the barchart and the calculate the mean. I think for the mean calculation, I have to use the audio stop and start columns.

Accepted Answer

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 19 Jun 2021
Edited: Sulaymon Eshkabilov on 19 Jun 2021
Simply to use bar():
DD = readtable('Data extracted- Lab.xls');
DD = readtable('Data extracted- Lab.xls');
Mean_A =DD.AudioStartTime;
Mean_V =DD.VideoStart;
figure
bar(DD.AudioStartTime)
figure
bar(DD.VideoStart)
...
  2 Comments
Siddharth Satishchandran
Siddharth Satishchandran on 19 Jun 2021
Thank you. Using Matlab, How would I go about calculating the mean call rate fir the 1st, second and third animals? I think for that I would add up the audio start and stop times for each individual and divide by the total session duration to get the mean? The postdoc I am working under told me that for session duration I can use the last value for the audio stop time.
Siddharth Satishchandran
Siddharth Satishchandran on 19 Jun 2021
The code you sent doesnt seem to be working. The response I get when typing in DD = readtable('LabelTable.mat'):
Error using readtable (line 318)
'.mat' is not a recognized file extension. Unable to detect file type. To read the file as a specific file type, regardless of file
extension, use the 'FileType' name-value pair.
DD = readtable('LabelTable.mat');
Error using readtable (line 318)
'.mat' is not a recognized file extension. Unable to detect file type. To read the file as a specific file type, regardless of file
extension, use the 'FileType' name-value pair.

Sign in to comment.

More Answers (6)

Siddharth Satishchandran
Siddharth Satishchandran on 19 Jun 2021
Edited: Image Analyst on 19 Jun 2021
Also for matlab, how would I go about uploading a matlab data file? The code I am using is a variation of this:
load('/Users/ameliachang/Downloads/LabelTable.mat'))
but in place of the postdoc's name I put my name. But the response I get is:
load('/Users/siddharthsatishchandran/Downloads/LabelTable.mat'))
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters
For the bar chart, each individual and their mean call rate have to be represented. The barchart has to look like this, but with each of the three indivduals on the bottom and calls/min on the side.
  2 Comments
Image Analyst
Image Analyst on 19 Jun 2021
The file you uploaded had only 3 lines of data - not enough to get averages for all those call types and categories. Please upload an actual file with lots of data in it.
Siddharth Satishchandran
Siddharth Satishchandran on 19 Jun 2021
I have included the actual data. It is a Matlab data file to be uploaded into Matlab to access the table of values. The postdoc I am working under however, told me that I had to practice by writing 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, you can use the last value of the "AudioStopTime" column. I have to also create a bar chart showing the call rate for each animal.

Sign in to comment.


Siddharth Satishchandran
Siddharth Satishchandran on 19 Jun 2021
When trying to upload the dataset from LabelTable.mat, using load('/Users/ameliachang/Downloads/LabelTable.mat'))
I still get this response:
load('/Users/siddharthsatishchandran/Downloads/LabelTable.mat'))
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 19 Jun 2021
Error in your command syntax:
load('/Users/ameliachang/Downloads/LabelTable.mat') % one ) has to be removed.
  1 Comment
Siddharth Satishchandran
Siddharth Satishchandran on 19 Jun 2021
Hmm.. I changed it but an error occurred:
Error using load
Unable to read file '/Users/siddharthsatish/Downloads/LabelTable.mat'. No such file or directory.
But its in the downloads folder of my laptop

Sign in to comment.


Sulaymon Eshkabilov
Sulaymon Eshkabilov on 19 Jun 2021
load('C:\Users\siddharthsatish\Downloads\LabelTable.mat') % Fix directory: C:\ or D:\
  2 Comments
Siddharth Satishchandran
Siddharth Satishchandran on 19 Jun 2021
I dont know if it helps but I have a Macbook. When I was sent the data file, it was downloaded into my downloads folder. I was able to import it into my Matlab but I cant seem to load it.

Sign in to comment.


Sulaymon Eshkabilov
Sulaymon Eshkabilov on 19 Jun 2021
Ok. Well Mac has a different syntax for directory specs.
In that case, you can change the directory and then load the data file. Try this:
cd ~/ameliachang/'Downloads'
You may also try using "Finder" to find the folder, right-click on it, and then click "Get Info".
  3 Comments
Siddharth Satishchandran
Siddharth Satishchandran on 19 Jun 2021
The response I recieved is:
Error using cd
Unable to change current folder to '/home/mluser/siddharthsatish/Downloads' (Name is nonexistent or not a folder).
Siddharth Satishchandran
Siddharth Satishchandran on 19 Jun 2021
Its in my downloads folder on my Macbook but I still cant load it into matlab. Would I be able to change it from .mat to a csv file?

Sign in to comment.


Sulaymon Eshkabilov
Sulaymon Eshkabilov on 19 Jun 2021
cd ~/home/mluser/siddharthsatish/'Downloads' % Watch where apostrophe signs ' ' are placed
  4 Comments
Sulaymon Eshkabilov
Sulaymon Eshkabilov on 20 Jun 2021
Just put your *.mat file into your MATLAB directory, then you can load all your data with one simple command, e.g.:
load('LabelTable.mat')
Siddharth Satishchandran
Siddharth Satishchandran on 20 Jun 2021
To import a single .mat file into matlab workspace/directory do i use load LabelTable.mat or is it
file = dir('*.txt');

Sign in to comment.

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!