Optimization of manipulating an array
Mostra commenti meno recenti
I have an array, where 0s are between non-zeros integer or floating numbers.
>> a = [1, 0, 5, 0, 6, 0, 12, 0];
I am looking to find the average of every adjacent two numbers and insert it to replace the zero between them:
like for the example above:
>> b = [1, 3, 5, 5.5, 6, 9, 12, 15]
For the last 0, we should add the difference between 12 and 9 to the last value, which is 12. So that makes (12 - 9) + 12.
I am looking for an optimized code (may be if possible without loop).
Thanks
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Get Started with Optimization Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!