how to get the array values using as index of another array values

1 visualizzazione (ultimi 30 giorni)
N=10
for i=1:N
format shortg
tmp = clock;
out(i,:) = tmp([5,6])
end
in_zone=nonzeros(zone);
out =
35 8.347
35 8.351
35 8.355
35 8.359
35 8.362
35 8.366
35 8.37
35 8.376
35 8.379
35 8.383
35 8.387
35 8.39
35 8.393
35 8.396
35 8.4
in_zone =
2
3
4
6
8
10
now i wish to store the out value acooarding to in_zone value in the array example below
new_array=
2 35 8.351
3 35 8.355
4 35 8.359
6 35 8.366
8 35 8.376
10 35 8.383
  1 Commento
Stephen23
Stephen23 il 4 Mag 2015
Modificato: Stephen23 il 4 Mag 2015
Do not place the format call inside the loop! format only needs to be called once and its new setting will apply to the entire MATLAB session. Read more about it in the documentation:
Also note that you should not use i or j as variable names, as these are both names of the inbuilt imaginary unit.

Accedi per commentare.

Risposte (1)

Stephen23
Stephen23 il 4 Mag 2015
Modificato: Stephen23 il 4 Mag 2015
Just use the in_zone values as row indices like this:
new array = [in_zone, out(in_zone,:)]

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by