how can I find the elements in the matrix that meet my conditions and then form the matrix within these conditions?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hallo everybody, I have a matrix of latitudes of earth locations from pool to pool obtained from a satellite pass. the matrix is 20x2573 double with many values set as NaN. I need only the latitudes of the Mediterranean Sea: 28°N to 46°N Latitude. Does anyone knows how I can limit my matrix to only the latitudes needed without changing the shape of it. that means the rows must stay 20 because they refer to 20 herz values and with NaN values too. Big thanks in advance!
댓글 수: 3
Guillaume
2018년 9월 25일
Ok, but you need to explain better what limit the matrix actually mean.
It could mean that you want to keep columns 87 to 222, i.e any column that has values in the closed interval [24, 46] (or is it half-closed interval [24, 47) ?)
It could mean the same, but for the edge columns, any value out of the interval is replaced by NaN.
It could be that you want to keep columns whose median or mean is within your interval.
Something else altogether?
채택된 답변
Stephan
2018년 9월 25일
편집: Stephan
2018년 9월 25일
Hi,
here is an example:
% Make a random Matrix with 50x3 random integers between 1...100
A = randi(100,50,3);
% Use only the rows of A for B, where in column 1 of A the values are between 28 and 46
B = A(A(:,1)>=28 & A(:,1)<=46,:)
EDIT:
For your case this should work:
keep_col = sum(lat >= 28 & lat <= 46) >= 1;
lat2 = lat(:,keep_col);
You get a 20x136 Matrix lat2 which meets the condtions and all NaN values are kept.
Best regards
Stephan
댓글 수: 7
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!