Script for a sum of value drive by rules

1 回表示 (過去 30 日間)
Julien Boulay
Julien Boulay 2015 年 8 月 21 日
Hi!
I have a matrix of data with only 0 and 0.2 values. I need to have the sum of successive 0.2 values (delta) for each columns of my matrix. Example: col1= 0 0 0 0.2 0.2 0.2 0.2 0 0 0.2 0 0.2 0.2 and the result_col1= 0.8 0.2 0.4. I write a script that works very well to do this (see above). First little problem, how can I say to my script that you need to read all columns of my matrix and put each correspondant delta values in my final matrix d?
Then, I would like to have a rule saying to the script "when you saw less than five zeros successively don't stop to calculate delta". In my script, the calculation of delta stop when the script saw only one zero after a 0.2 value.
Thanks a lot. Julien
T = importdata('data.xls')
T= T.Feuil1;
d(1,:) = zeros(1,size(T,2));
j=1;
for individu=1:size(T,2)
for i=1:size(T,1);
if T(i,individu)== 0.2 || any(T(1:i))==0
d(j,individu) = d(j,individu)+T(i,individu);
elseif T(i)==0 && T(i-1)== 0.2
j= j+1;
d(j,individu) = 0;
end
end
j=1;
end

回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by