2013-01-02 70 views
0

我對編碼的想法有問題。任何幫助都是很好的。獲取趨勢矩陣,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和vice vers。

任何想法請

%% 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' ] 
+2

「即將到來」或「正在下降」是如何定義的? Output_'第一列中的索引對應於什麼? –

+0

親愛的,水浪越過30限制,那麼40也因此在8,我們得到兩個值。現在它已越過40,下一個值是大於79小於84,所以趨勢是STIL下來,然後波出現時,第一交叉40,然後在30,所以agian 2個值。 – Shahgee

+0

親愛的:我的問題和意見,我所提到的價值是絕對的「%的值是ABS」 – Shahgee

回答

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) | 
+0

@ slitvinov感謝名單非常多,但是我們可以看到你的輸出遠離我Output_。無論如何thanx再次。我必須尋找一些無聊的..如果循環。 – Shahgee