How to assign variables based on index position
19 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I want to assign a variable based on index position
a = [1 1 1 1 1.6 1.1 1.1 1.6 1.1 1.1]
find(a > 1.5)
This gives me the position of those values in the array
ans =
5 8
I then want to assign them a variable such that gap1 = 5, gap2 = 8 to gap(n) = #
Following this, I want to apply these variables
getNPVI(a(1:gap1 - 1))
getNPVI(a(gap1 + 1:gap2 - 1))
until getNPVI(a(lastgap + 1:end))
Any guidance is appreciated, thank you.
0 Commenti
Risposte (2)
Samuel Londner
il 1 Dic 2019
Modificato: Samuel Londner
il 1 Dic 2019
For the assignment problem I would try something like that:
kk = a > 1.5;
indexes = 1:length(a);
out = a*(~kk) + indexes * kk;
For your second problem try using a Hankel matrix as an index matrix. A simple "for" loop would also do the trick.
0 Commenti
KALYAN ACHARJYA
il 1 Dic 2019
Modificato: KALYAN ACHARJYA
il 1 Dic 2019
One way:
a = [1 1 1 1 1.6 1.1 1.1 1.6 1.1 1.1]
result=find(a > 1.5)
Now access the result data as result(1) and result(2) ..array indexing is recomended rather than different variable names
0 Commenti
Vedere anche
Categorie
Scopri di più su Matrices and Arrays in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!