Extracting values from a matrix
8 views (last 30 days)
Show older comments
MEHDI HAMIDI
on 13 May 2022
Commented: MEHDI HAMIDI
on 14 May 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 Comments
dpb
on 13 May 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
Accepted Answer
Image Analyst
on 13 May 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 Comments
Jan
on 14 May 2022
@MEHDI HAMIDI: Or simpler without a loop:
SortedData = sort(Data, 2, 'descend')
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!