필터 지우기
필터 지우기

Extracting values from a matrix

조회 수: 7 (최근 30일)
MEHDI HAMIDI
MEHDI HAMIDI 2022년 5월 13일
댓글: MEHDI HAMIDI 2022년 5월 14일
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
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
MEHDI HAMIDI
MEHDI HAMIDI 2022년 5월 13일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
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
Jan 2022년 5월 14일
@MEHDI HAMIDI: Or simpler without a loop:
SortedData = sort(Data, 2, 'descend')
MEHDI HAMIDI
MEHDI HAMIDI 2022년 5월 14일
Yes that works also thanks for sharing with me your solution i really appreciate it sir

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by