0

コーディングのアイデアに問題があります。どんな助けでも大歓迎です。

マトリックスがあり、傾向を示す必要があります。

Limit1=30;
limit2=40;
F=[0 ; 0; 0; 0; 0; 0 ; 1; -79; -84; 35 ; 75; 0 ;0 ]
[row1,col1,v1] = find(abs(F)>30)
[row2,col2,v2] = find(abs(F)>40)

Limit1 を超えると、Limit2 もチェックする必要があり、その逆も必要です。

任意のアイデアをお願いします

%% OutPut=[ row_of_F,Value_crossing_which_limit(Limit1,Limit2), trend (from lower to upper or vice versa] % values are abs – user31177 1 min ago edit

%% これは出力されるはずです

 OutPut_=[ '8'     '30'    'GoingDown'
'8'     '40'    'GoingDown'
'9'     '40'    'GoingDown'
'10'    '40'    'Comingup' 
'11'    '30'    'GoingDown'
'11'    '40'    'GoingDown'
'12'    '40'    'Comingup' 
'12'    '30'    'Comingup' ]
4

1 に答える 1

1

このアプローチはどうですか?

% your data
F=[0 ; 0; 0; 0; 0; 0 ; 1; -79; -84; 35 ; 75; 0 ;0];

% growth state
growthstate = [0; sign(diff(F))];

% state relative to the lim1
% true if crossing lim1
lim1=30;
lim1state_p =  [false; diff(F-lim1>0)];
lim1state_n =  [false; diff(F+lim1>0)];
lim1state = lim1state_p | lim1state_n

% the same for lim2
% true if crossing lim2
lim2=40;
lim2state_p =  [false; diff(F-lim2>0)];
lim2state_n =  [false; diff(F+lim2>0)];
lim2state = lim2state_p | lim2state_n;

% decod growth state
s{1}='GoingDown';
s{2}='GoingUp';
decode = @(idx) s{double(idx>0) + 1};

c = {};
for k=1:length(F)
  if lim1state(k)
    c(end+1,:) = {F(k-1), F(k), k, lim1, decode(growthstate(k))};
  end
  if lim2state(k)
    c(end+1,:) = {F(k-1), F(k), k, lim2, decode(growthstate(k))};
  end
end

% show
c

プログラムの出力に注釈を付けました。

| F(k-1) | F(k) |  k | level |           | reason                 |
|--------+------+----+-------+-----------+------------------------|
|      1 |  -79 |  8 |    30 | GoingDown | cross -30,F(k)<F(k-1)  |
|      1 |  -79 |  8 |    40 | GoingDown | cross -40,F(k)<F(k-1)  |
|    -79 |  -84 |  9 |     - | -         | no crossing            |
|    -84 |   35 | 10 |    30 | GoingUp   | cross -30, F(k)>F(k-1) |
|    -84 |   35 | 10 |    40 | GoingUp   | cross -40, F(k)>F(k-1) |
|     35 |   75 | 11 |    40 | GoingUp   | cross 40, F(k)>F(k-1)  |
|     75 |    0 | 12 |    30 | GoingDown | cross 30, F(k)<F(k-1)  |
|     75 |    0 | 12 |    40 | GoingDown | cross 40, F(k)<F(k-1)  |
于 2013-01-02T18:06:21.500 に答える