Index and sort through vector by only picking the values that are the same
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tyler Ram
am 8 Nov. 2018
Kommentiert: Star Strider
am 8 Nov. 2018
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 Kommentare
Akzeptierte Antwort
Star Strider
am 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 Kommentare
Star Strider
am 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!