How to select specific values and corresponding cell positions from 31 x 12 matrix?

조회 수: 4 (최근 30일)
Hi,
I have 31 x 12 matrix (A) with daily temperature for one year. Values range between 10.2 and 39°C.
How to find a new metrix B (? x 12) with all values (in each column) less than 1.15 times minimum value (ie. < 10.2*1.15) and corresponding cell positions?
Thanks in advance.
  댓글 수: 1
Parthu P
Parthu P 2019년 11월 6일
Hi,
I have 31 x 12 matrix (A) with daily temperature for one year. Values range between 10.2 and 39°C.
How to find a new metrix B (? x 12) with all values (in each column) less than 1.15 times minimum value (ie. < 10.2*1.15) and corresponding cell positions?
Thanks in advance.

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

채택된 답변

Fabio Freschi
Fabio Freschi 2019년 11월 6일
편집: Fabio Freschi 2019년 11월 6일
Because the number of rows in B is not fixed, you can store the result of your check in a cell array
% create the matrix
A = (39-10.2)*rand(31,12)+10.2;
% tolerance
tol = 1.15;
% get minimum
minA = min(A(:));
% cell array with required entries
B = arrayfun(@(i)A(A(:,i) < tol*minA,i),1:size(A,2),'UniformOutput',false);
You can now access your data using B{i}, where i is the index of the month
You can also get the pointers to the desired data using find
[iDay,jMonth] = find(A < tol*minA);
  댓글 수: 3
Parthu P
Parthu P 2019년 11월 6일
Sorry. It's B. It should have more than one row(s). But when I use above functions with different tolarance values, B only show single row (1 x 12) output. But I need multiple rows in all 12 columns. What other functions I should try?
Fabio Freschi
Fabio Freschi 2019년 11월 7일
B has only one row, but each cell contains all values oq your query:
>> B
B =
1×12 cell array
Columns 1 through 6
{5×1 double} {2×1 double} {0×1 double} {2×1 double} {[10.4252]} {0×1 double}
Columns 7 through 12
{2×1 double} {[10.7914]} {2×1 double} {4×1 double} {[11.4044]} {2×1 double}
as you can see, for example, B{1} has 5 entries.
How do you expect to have B if the different montsh can have a different number of days with temperature below your threshold? In other words, what is the size of the expexted output?
Another thing you can do is to have a 31 x 12 B matrix, where all values above the threshold are set to zero or NaN. In this case you can use
B = A;
B(A >= tol*minA) = 0;

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by