Question Regarding Sorting of the elements

9 Ansichten (letzte 30 Tage)
Abeer Abdelhadi
Abeer Abdelhadi am 13 Dez. 2018
Kommentiert: Stephen23 am 13 Dez. 2018
say I have vector [ 4 2 6] representing indicies and each of them has values V1= [ 5 9 1]
and I have another vector [ 1 5 3 ] again representing indicies and each of them has the corresponding values v2= [ 0 0 0 ]
What I want is to rearrange the CORRESPONDING values of the indicies combined( in ascending order of the indicies) which would get me a vector as follows :
X = [ 0 9 0 5 0 1]
How can i get vector X ?

Antworten (1)

Stephen23
Stephen23 am 13 Dez. 2018
>> X1 = [ 4 2 6];
>> V1 = [ 5 9 1];
>> X2 = [ 1 5 3];
>> V2 = [ 0 0 0];
>> X(X1) = V1;
>> X(X2) = V2
X =
0 9 0 5 0 1
  2 Kommentare
Abeer Abdelhadi
Abeer Abdelhadi am 13 Dez. 2018
works perfectly ! thanks
Stephen23
Stephen23 am 13 Dez. 2018
@Abeer Abdelhadi: I hope that it helps. Don't forget to accept my answer!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by