About function in methods of a class
古いコメントを表示
Hi guys, I'm doing a project.
To use function in methods of one of my class I defined, I made this one :
function [y, Fs] = getRandomMusic(feeling)
path_name = strcat('C:\Users\Jack\Desktop\music','\',feeling);
music_lists = dir(path_name);
music_number = length(music_lists);
ran_music_number = randi(music_number);
while ran_music_number < 3
ran_music_number = randi(music_number);
end
file_name = strcat(path_name,'\',music_lists(ran_music_number).name);
[y, Fs] = Audioread(file_name, native);
end
This is the function when input "feeling", then it returns [y, Fs] of randomly selected from the "feeling" folder.
But when I rud the main MATALB file to use this function, it makes an error messgae like this :
Check the function 'getRandomMusic' for missing arguments or invalid argument data types. (It's not official message cuz my mother tongue isn't english)
Can anyone suggest something to me?
Thanks!
3 件のコメント
per isakson
2020 年 9 月 28 日
I don't get the big picture. What does "use function in methods" mean?
Use the function fullfile() instead of strcat() to create full file specifications.
Replace Audioread() by audioread()
Tony Kaywood
2020 年 9 月 28 日
per isakson
2020 年 9 月 28 日
"defined function in class file" There is a problem with nomenclature. In Matlab methods of classes are defined with the keyword, function.
classdef MyClass
methods
function [y,Fs] = getRandomMusic( obj, feeling )
end
end
end
In this basic case you have to take the instance variable, obj, as the first input argument.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Function Handles についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!