Function that creates an array of specified size from a first value where each next value is a multiple of the previous value?
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
For example, if given 20 as first value, 0.75 as percent of first value and length or size 4 would produce:
[20,15,11.25,8.4375]
or essentially
[20,20*0.75,20*0.75^2,20*0.75^3]
for a more generalized version I was able solve this problem with a for loop, but I am curious if there is a built in function to accomplish this task?
1 comentario
Stephen23
el 19 de Jun. de 2015
The most "generalized version" in MATLAB is not using a loop, but using vectorized code like Azzi Abdelmalek has shown below. MATLAB is not a low-level language like C that relies on loops for everything: vectorized code is much more efficient in MATLAB!
Respuestas (1)
Azzi Abdelmalek
el 18 de Jun. de 2015
Editada: Azzi Abdelmalek
el 18 de Jun. de 2015
n=4
p=0.75
out=20*p.^(0:n-1)
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!