Shorten code for a function

1 visualización (últimos 30 días)
Tino
Tino el 15 de Mayo de 2019
Comentada: madhan ravi el 15 de Mayo de 2019
Hi
Please I have this function
fnP=@(a,i)(sum(a(i)>a(1:i))+0.5*sum(a(i)==a(1:i)))/i;
and I get generated result for each column
for instance
m1 = fnP(result, 1)
m2 = fnP(result, 2)
m3 = fnP(result, 3)
.
.
.
mn =fnP(result, n)
and so on
I will like a short code that will give me the m results without having to repeat m1, m2, m3 , m4... etc the code for 800 column datapoint
Thanks in advance
Tino
  1 comentario
Stephen23
Stephen23 el 15 de Mayo de 2019
@Tino: using numbered variables is a sign that you are doing something wrong. It is simpler and much more efficient to use indexing into one array.

Iniciar sesión para comentar.

Respuesta aceptada

madhan ravi
madhan ravi el 15 de Mayo de 2019
m=cell(5,1);
for k=1:5
m{k}=fnP(result,k);
end
  3 comentarios
Tino
Tino el 15 de Mayo de 2019
Hi Madhan
How do I refer to the cell of m
for instance I want to want to use the code
x = m(: , :) ^ (2 * 5.2)
I am getting the error. Unable to use value of type 'cell' as an index
How do I go about it
thanks in advance
madhan ravi
madhan ravi el 15 de Mayo de 2019
x = [m{:}] .^ (2 * 5.2)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by