How to select cell values and cell positions from a matrix?
9 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a set of six month daily data (attached) in matrix (A) (31 x 6 size).
I used [cell_value, cell_position] = min(A,[],1) to find minimum value (cell value) and corresponding cell position in each column of A. I got two metrices:
- cell_value (1 x 6);
- cell_position (1 x 6);
I want two more metrices, "new_cell_value" and "new_cell_positions" such that,
3. new_cell_value - should have all the values less than 1.5*cell_value (row size of this matrix is unknown but has 6 columns), and
4. new_cell_positions of new_cell_value (row size of this matrix is unknown but has 6 columns).
The data is attached. Please help me to solve this.
Thanks in advance.
采纳的回答
Suleman ZP
2019-11-7
编辑:Suleman ZP
2019-11-7
You find mininum cell value and position with this line of code.
[cell_value, cell_position] = min(A,[],1);
and its results 1 row with 6 columns like this.
cell_value =
90.8900 71.9900 136.0800 120.4500 115.6900 121.9400
cell_position =
13 1 22 25 28 29
Now using below code we can found all values less than 1.15.*cell_value in each columns.
new_cell_positions = zeros(size(A));
new_cell_values = zeros(size(A));
B = A < 1.15.*cell_value;
for i = 1:6
loca = find(B(:,i) == 1);
new_cell_positions(1:length(loca),i) = loca;
new_cell_values(1:length(loca),i) = A(loca,i);
end
this results in random number of rows but fix 6 columns.
new_cell_values =
91.5800 71.9900 154.8600 135.8900 124.0500 140.0400
90.8900 0 150.4500 132.4300 122.9100 138.4500
92.0800 0 153.3600 127.5200 116.3900 138.1300
99.4600 0 155.6300 123.2600 115.6900 137.9900
0 0 155.6900 120.4500 116.6400 135.8200
0 0 152.6400 120.9000 115.8600 137.0000
0 0 145.3900 121.3700 0 132.1700
0 0 151.4300 123.2700 0 127.9400
0 0 149.5000 123.8800 0 126.9800
0 0 136.6300 124.5200 0 127.9400
0 0 140.7500 0 0 129.0600
0 0 146.2000 0 0 131.1200
0 0 154.8700 0 0 129.5800
0 0 136.0800 0 0 126.6600
0 0 141.1900 0 0 125.1200
0 0 153.2900 0 0 121.9400
0 0 0 0 0 121.9700
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
new_cell_positions =
12 1 1 21 25 1
13 0 2 22 26 2
14 0 3 23 27 3
31 0 4 24 28 4
0 0 5 25 29 5
0 0 6 26 30 19
0 0 7 27 0 20
0 0 8 28 0 21
0 0 11 29 0 22
0 0 12 30 0 23
0 0 13 0 0 24
0 0 14 0 0 25
0 0 15 0 0 26
0 0 22 0 0 27
0 0 23 0 0 28
0 0 30 0 0 29
0 0 0 0 0 30
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
4 个评论
Suleman ZP
2019-11-11
Can you please share the out of this line. So I can compare and understant the issue. B = A < 1.15.*cell_value;
更多回答(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!