How to code for Barchart and mean in matlab

조회 수: 5 (최근 30일)
Siddharth Satishchandran
Siddharth Satishchandran 2021년 6월 19일
댓글: Siddharth Satishchandran 2021년 6월 20일
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 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