-3

I am trying to find the minimum pressure by a specific storm id and assign that a value of one. I tried using a nested for loop with an if statement, but this is not working. Below is my code, and if you could help out, that would be great!

lifecycle = zeros(285,1);                    %// variable lifecycle denotes max storm intensity

for c = 1:285                                %// counter
    for id = 188:100:1288                    %// loop through each storm code(188,288,...1288)
       if min_press(c) == min(min_press(id)) %// find min pressure of each id 
           lifecycle(c) = 1;                 %// assign min a value of 1 
       end
    end
end 
Justin Fletcher
  • 2,319
  • 2
  • 17
  • 32
runnere127
  • 21
  • 3
  • 1
    What is `mean_press` then? Please post an [mcve](http://stackoverflow.com/help/mcve). – kkuilla Jun 16 '14 at 15:50
  • min_press = minimum pressure; a variable defined from my dataset (ebtrk)in previous code, given as follows: min_press = ebtrk(:,8); %minimum pressure (hPa) – runnere127 Jun 16 '14 at 15:54
  • The above code does not make sense. By your problem statement you would naturally assume that `min_press` would be a 2D matrix. The rows are subsetted by `c` while the columns are subsetted by `id`. By your comment above, `min_press` is only a column vector. – rayryeng Jun 17 '14 at 03:37
  • You haven't posted a sample of `min_press` so it is impossble to run your code and work out why it fails. That's why I suggested that you post an [mcve](http://stackoverflow.com/help/mcve). It will definitely increase your chances of a useful answer. – kkuilla Jun 17 '14 at 07:44
  • Sorry- new to matlab and stackoverflow. Here is sample of min_press '1015' '1014' '1013' '1012' '1011' '1009' '1006' '1002' '1002' '1008' – runnere127 Jun 18 '14 at 15:29

1 Answers1

1

Assuming your min_press variable is a 2D matrix with the minimum pressure represented as column vectors, you could do something like this.

A is your pressure values

A= randn(3,3)

  -0.063413  -2.130337   0.590931
   0.233517  -0.112800  -0.898581
  -0.395259   0.303704   2.508438

min() works on a columnn-by-column basis so taking the minimum value of the matrix will give you the minimum value for each column

[val, row] = min(A)

val =

-0.39526  -2.13034  -0.89858

row =

3   1   2    

Convert those in into indices related to the matrix A

 ind = sub2ind(size(A),row.', [1:length(row)].')

ind =

   3
   4
   8

Apply them to A

A(ind) = 0

A =

  -0.06341   0.00000   0.59093
   0.23352  -0.11280   0.00000
   0.00000   0.30370   2.50844
kkuilla
  • 2,226
  • 3
  • 34
  • 37