Borrar filtros
Borrar filtros

Help with creating a function

2 visualizaciones (últimos 30 días)
Adam
Adam el 22 de Jun. de 2013
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 comentarios
Adam
Adam el 23 de Jun. de 2013
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 el 23 de Jun. de 2013
Editada: dpb el 23 de Jun. de 2013
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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by