Why the function that I created won't be called?

24 ビュー (過去 30 日間)
Suha Ali Alshammari
Suha Ali Alshammari 2020 年 8 月 12 日
I have a code that convert text to speech, I added the "function" keyword to it so it became a function. When I run it as a function, it works perfectly!
But I am struggling to call that function in another script I wrote -with the intention of making use of the function I made by calling it- but to no vail! it can not be called ;( when I type its name in the other script, it just seems like its an ordinary word and not a function!
the error I get is: >> eegamplitude
Error using relaxed
Too many output arguments.
Error in eegamplitude (line 4)
A = relaxed;
although I'm pretty sure that I created it correctly and that the new script is being run in the same folder where the function file is stored!
PLEASE help! it is urgent ;( Thanks to whoever answers, in advance <3
%relaxed function
function relaxed
userPrompt = 'Enter the TEXT';
titleBar = 'Text to Speech';
defaultString = 'I am relaxed!';
caUserInput = inputdlg(userPrompt, titleBar, 1, {defaultString});
if isempty(caUserInput)
return;
end;
caUserInput = char(caUserInput);
NET.addAssembly('System.Speech');
obj = System.Speech.Synthesis.SpeechSynthesizer;
obj.Volume = 100;
Speak(obj, caUserInput);
end
%stressed function
function stressed
userPrompt = 'Enter the TEXT';
titleBar = 'Text to Speech';
defaultString = 'I am stressed!';
caUserInput = inputdlg(userPrompt, titleBar, 1, {defaultString});
if isempty(caUserInput)
return;
end;
caUserInput = char(caUserInput);
NET.addAssembly('System.Speech');
obj = System.Speech.Synthesis.SpeechSynthesizer;
obj.Volume = 100;
Speak(obj, caUserInput);
end
%the code that I thought I can call my functions with
function eegamplitude
for m = 1:6
if m < 4
A = relaxed;
else A =stressed;
end
A
end
end

採用された回答

Steven Lord
Steven Lord 2020 年 8 月 12 日
From the error message you showed, on line 4 of eegamplitude you're calling relaxed with 0 input arguments and 1 output argument.
Let's look at the definition of relaxed.
%relaxed function
function relaxed
This function is defined to accept a maximum of 0 input arguments and return a maximum of 0 output arguments.
See the section "Syntax for Function Definition" on this documentation page for instructions on how to define a function that returns output arguments. Or, if relaxed is supposed to not return any output arguments, remove the output argument from your call to relaxed on line 4 of eegamplitude.
  1 件のコメント
Suha Ali Alshammari
Suha Ali Alshammari 2020 年 8 月 12 日
Thank you so much for your answer! <3

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

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2020 年 8 月 12 日
Your function "relaxed" does not have any return values so you can't do "A=relaxed" because "A" can't be assigned. That is the error message.
  1 件のコメント
Suha Ali Alshammari
Suha Ali Alshammari 2020 年 8 月 12 日
THANK YOU FROM THE BOTTOM OF MY HEART! your answer helped a lot!

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

カテゴリ

Help Center および File ExchangeText Analytics Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by