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

1 次查看(过去 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