How to code for Barchart and mean in matlab

5 次查看(过去 30 天)
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.

采纳的回答

Sulaymon Eshkabilov
编辑:Sulaymon Eshkabilov 2021-6-19
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 个评论
Siddharth Satishchandran
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
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.

请先登录,再进行评论。

更多回答(6 个)

Siddharth Satishchandran
编辑:Image Analyst 2021-6-19
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 个评论
Image Analyst
Image Analyst 2021-6-19
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
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.

请先登录,再进行评论。


Siddharth Satishchandran
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
Error in your command syntax:
load('/Users/ameliachang/Downloads/LabelTable.mat') % one ) has to be removed.
  1 个评论
Siddharth Satishchandran
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

请先登录,再进行评论。


Sulaymon Eshkabilov
load('C:\Users\siddharthsatish\Downloads\LabelTable.mat') % Fix directory: C:\ or D:\
  2 个评论
Siddharth Satishchandran
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.

请先登录,再进行评论。


Sulaymon Eshkabilov
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 个评论
Siddharth Satishchandran
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
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?

请先登录,再进行评论。


Sulaymon Eshkabilov
cd ~/home/mluser/siddharthsatish/'Downloads' % Watch where apostrophe signs ' ' are placed
  4 个评论
Sulaymon Eshkabilov
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
To import a single .mat file into matlab workspace/directory do i use load LabelTable.mat or is it
file = dir('*.txt');

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Performance and Memory 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by