Extracting values from a matrix
조회 수: 8 (최근 30일)
이전 댓글 표시
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
dpb
2022년 5월 13일
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
채택된 답변
Image Analyst
2022년 5월 13일
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
Jan
2022년 5월 14일
@MEHDI HAMIDI: Or simpler without a loop:
SortedData = sort(Data, 2, 'descend')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!