Azzera filtri
Azzera filtri

Extracting values from a matrix

7 visualizzazioni (ultimi 30 giorni)
MEHDI HAMIDI
MEHDI HAMIDI il 13 Mag 2022
Commentato: MEHDI HAMIDI il 14 Mag 2022
Hi Hello, i hope eveyrone is doing good, i have a matrix (6100,1000) and i would like to extract some values , the rows of my matrix contains values but most of it's -300, e,g first row ( -300 -300 -300 ......... -124 -300 -300 -300) so i would like to extract 10 values that are not equal to -300, but in the case where i dont have other values i can take -300 only to fill it, basically i would like to do this for my whole matrix
thank you
  2 Commenti
dpb
dpb il 13 Mag 2022
You know what your intent is; we don't except by the description you post. There's too much not explained here -- for example, are you just wanting some number of values out of the total number that are in the file, selecting all of those that aren't -300 first irrespective of their position in the file? Or do you want the rows that have something other than -300 by row; a specific number of rows overall? Or...???
Give us a an example -- explain precisely what your expected output would be.
It would help to have a sample file -- attach a .mat file
MEHDI HAMIDI
MEHDI HAMIDI il 13 Mag 2022
So, what i want, is to extract the 10 first not -300 values if there is, if there is not 10 values that are not equal to -300 i will take the -300 values only to fill my vector, the output should be 6100 vectors with a size of 10
i hope it is clear now

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 13 Mag 2022
Do they need to be in any particular order? Otherwise just sort and take the first 10 elements. Like for a single row, do this:
sortedValues = sort(oneRow, 'descend');
first10 = sortedValues(1:10);
Can you supply a sample matrix?
  7 Commenti
Jan
Jan il 14 Mag 2022
@MEHDI HAMIDI: Or simpler without a loop:
SortedData = sort(Data, 2, 'descend')
MEHDI HAMIDI
MEHDI HAMIDI il 14 Mag 2022
Yes that works also thanks for sharing with me your solution i really appreciate it sir

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by