Function that creates an array of specified size from a first value where each next value is a multiple of the previous value?
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
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 Kommentar
Stephen23
am 19 Jun. 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!
Antworten (1)
Azzi Abdelmalek
am 18 Jun. 2015
Bearbeitet: Azzi Abdelmalek
am 18 Jun. 2015
n=4
p=0.75
out=20*p.^(0:n-1)
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!