필터 지우기
필터 지우기

How to select cell values and cell positions from a matrix?

조회 수: 21 (최근 30일)
Parthu P
Parthu P 2019년 11월 7일
댓글: Suleman ZP 2019년 11월 11일
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:
  1. cell_value (1 x 6);
  2. 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.
  댓글 수: 2
Stephen23
Stephen23 2019년 11월 7일
What have you tried so far?
Parthu P
Parthu P 2019년 11월 7일
Thank you for response.
I tried
[cell_value, cell_position] = min(A,[],1) to find minimum value (cell value) and corresponding cell position in each column of A - it worked very well
I then tried
B = find(A >== 1.15.*cell_value(:,6));
This doesn't give any error but it reads intended values incorrectly (in between A and 1.15.*cell_value). I need all values from A less than "1.15.*cell_value".

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

채택된 답변

Suleman ZP
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
Parthu P
Parthu P 2019년 11월 7일
Hi Suleman,
Thanks very much for response. I really appreciate your time and effort.
Unfortunately, updated code makes new_cell_positions, new_cell_values, and B all-zero.
Rather previous code worked well but I had difficulty with "B = A < 1.15.*cell_value " in putting right dimensions.
Please help me with dimensions next to "cell_value" in "B = A < 1.15.*cell_value;" in the previous code.
Thank you in advance.
Suleman ZP
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by