获取趋势矩阵,matlab(概念)

时间:2013-01-02 15:50:09

标签: matlab

我对编码的想法有疑问。任何帮助都很好。

我有一个矩阵,我必须显示趋势。

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' ]

1 个答案:

答案 0 :(得分: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)  |