Index and sort through vector by only picking the values that are the same

4 visualizzazioni (ultimi 30 giorni)
H = [500 500 500 450 450 450 400 400 350 350 350 300 300 300];
I = [-0.0019 -0.0018 -0.0017 -0.0019 -0.0018 -0.0017 -0.0019 -0.0018 -0.0017]
V = [-7.54E-06 -7.23E-06 -6.93E-06 -7.53E-06 -7.21E-06 -6.89E-06 -6.60E-06 -7.50E-06 -7.23E-06 -6.90E-06]
Need to sort through the data and get an IV for each value but lump then off the uniqueness of their value, e.g., I want all the IVs for the H at 400, etc. I know there is a unique function in Matlab, but that only gives me a single element of the array that is unique. Is there a way to loop through the unique values to get the IV values?
Thanks,
Tyler
  5 Commenti
Tyler Ram
Tyler Ram il 8 Nov 2018
I attached a more full version, I am taking the data from an excel sheet, hopefully you can see this, the last one got flagged as spam

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 8 Nov 2018
The unique funciton can have 3 outputs, although you have to specifically request them. The third output is the index of each repeated unique value in the vector. You can use those to map into ‘I’ and ‘V’:
H = [500 500 500 450 450 450 400 400 350 350 350 300 300 300];
[Hu,~,idx] = unique(H, 'stable')
The 'stable' argument simply retains the original order, rather than sorting the output.
  2 Commenti
Tyler Ram
Tyler Ram il 8 Nov 2018
Do you know a simple way to sort through using your indexing method?
Star Strider
Star Strider il 8 Nov 2018
If you want to sort the result, just remove the 'stable' argument. The results and the associated ‘idx’ vector will then be sorted in ascending order.
If you want them sorted in descending order, it would be easiest to use the sort function to do that first, then use unique with the 'stable' argument.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Shifting and Sorting 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