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

5 ビュー (過去 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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by