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

1 Ansicht (letzte 30 Tage)
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 Kommentar
Parthu P
Parthu P am 6 Nov. 2019
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Fabio Freschi
Fabio Freschi am 6 Nov. 2019
Bearbeitet: Fabio Freschi am 6 Nov. 2019
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 Kommentare
Parthu P
Parthu P am 6 Nov. 2019
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 am 7 Nov. 2019
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;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by