How to code for Barchart and mean in matlab

5 ビュー (過去 30 日間)
Siddharth Satishchandran
Siddharth Satishchandran 2021 年 6 月 19 日
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 日
編集済み: 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
Siddharth Satishchandran 2021 年 6 月 19 日
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 2021 年 6 月 19 日
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
Siddharth Satishchandran 2021 年 6 月 19 日
編集済み: 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
Siddharth Satishchandran 2021 年 6 月 19 日
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
Siddharth Satishchandran 2021 年 6 月 19 日
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 2021 年 6 月 19 日
Error in your command syntax:
load('/Users/ameliachang/Downloads/LabelTable.mat') % one ) has to be removed.
  1 件のコメント
Siddharth Satishchandran
Siddharth Satishchandran 2021 年 6 月 19 日
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
Sulaymon Eshkabilov 2021 年 6 月 19 日
load('C:\Users\siddharthsatish\Downloads\LabelTable.mat') % Fix directory: C:\ or D:\
  2 件のコメント
Siddharth Satishchandran
Siddharth Satishchandran 2021 年 6 月 19 日
Neither C:\ or D:\ worked. I have attched a screenshot of the error
Siddharth Satishchandran
Siddharth Satishchandran 2021 年 6 月 19 日
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
Sulaymon Eshkabilov 2021 年 6 月 19 日
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
Siddharth Satishchandran 2021 年 6 月 19 日
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 2021 年 6 月 19 日
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
Sulaymon Eshkabilov 2021 年 6 月 19 日
cd ~/home/mluser/siddharthsatish/'Downloads' % Watch where apostrophe signs ' ' are placed
  4 件のコメント
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 6 月 20 日
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 2021 年 6 月 20 日
To import a single .mat file into matlab workspace/directory do i use load LabelTable.mat or is it
file = dir('*.txt');

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by