Passing array as an input argument

I want to pass an array [p1 p2 p3] in the function "arithmetic_decoding" as an input.
function arithmetic_decoding(tag,n,[p1,p2,p3]) % this shows error "Unbalanced or unexpected parenthesis or bracket"
Please help?
%p1=0.4;
%p2=0.5;
%p3=0.1;

 Respuesta aceptada

the cyclist
the cyclist el 6 de Oct. de 2019
Is that how you are calling the function, or is it the function header (inside the function file itself)?
If that is how you are calling the function, you don't want the word function there. Instead, use just
arithmetic_decoding(tag,n,[p1,p2,p3])
If that is the function header, then you'll need to do something like
function arithmetic_decoding(tag,n,p)
and then parse the p1,p2,p3 inside the function itself.

3 comentarios

Mayank Nautiyal
Mayank Nautiyal el 7 de Oct. de 2019
Editada: per isakson el 7 de Oct. de 2019
Hi, thanks for your time. I am using it as a function header.
function arithmetic_decoding(tag,n,p)
p=[p1 p2 p3];
end
% Is this what you mean? as this is not working
% I'm calling like this: arithmetic_decoding(0.572,3,[0.4 0.5 0.1])
per isakson
per isakson el 7 de Oct. de 2019
Editada: per isakson el 7 de Oct. de 2019
Why do you want to do this in the first place?
You'll need something like this
function arithmetic_decoding(tag,n,p)
p1 = p(1);
p2 = p(2);
p3 = p(3);
end
Mayank Nautiyal
Mayank Nautiyal el 7 de Oct. de 2019
Thanks it worked.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 6 de Oct. de 2019

Comentada:

el 7 de Oct. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by