필터 지우기
필터 지우기

Help with creating a function

조회 수: 2 (최근 30일)
Adam
Adam 2013년 6월 22일
Hi, I am new to Matlab and I am trying to create a function that takes a selected audio signal and segments it into different sections, labelling each section with a variable. I have started to create this function below but when I use it the variables don't appear in the workspace. Have I missed something in the function?
function [a1,a2,a3,a4,a5,a6,a7,a8,a9] = segment(FILE)
x = wavread(FILE);
a1 = x(1:20000);
a2 = x(20000:40000);
a3 = x(40000:60000);
a4 = x(60000:80000);
a5 = x(80000:100000);
a6 = x(100000:120000);
a7 = x(120000:140000);
a8 = x(140000:160000);
a9 = x(16000:180000);
end
  댓글 수: 13
Adam
Adam 2013년 6월 23일
Ahh ok I've got it now, that was really helpful, thanks for explaining that!
But how can I use say B2 for instance as the input of another function that I'm creating
function [d] = testFunction(variable{})
like that?
dpb
dpb 2013년 6월 23일
편집: dpb 2013년 6월 23일
I suggest reading up in the 'Getting Started' section and then the full documentation on functions to get a better overall handle on the syntax and calling conventions. Also, go to the section on Data Structures and read up on cell arrays and the section on how to address them.
As for passing anything to another function, you just include it in the argument list at the right location as expected by the called function (assuming order association rather than named arguments vis a vis oop methods). You do not include the braces or parens in the function definition.
As for passing the results of a function, sure if it is the type and size that the function is expecting. Note, however, that there's no way to assign multiple outputs from the called function in this context so the returned value "seen" by the called function will be that of the first returned variable only of the function if more than one are possible.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by