matlab - Script for a sum of value driven by rules -
thanks guys help. code:
clc; t = importdata('data_jana.xls'); result = cell(1, size(t,2)); col = 1:size(t,2) %// length-value pairs [lengths, values] = runlengthencode(t(:,col)); %// compute deltas deltas = 0.2*lengths(values == 0.2); %// remove deltas following 5 zeros idxfivezeros = find(lengths > 4 & values == 0, 1); if(isempty(idxfivezeros)) idxfivezeros = numel(lengths); end deltas = deltas(1:sum(values(1:idxfivezeros) == 0.2)); %// store result column result{col} = deltas; end
there no errors.
but problem script stop deltas calculation when found 5 zeros consecutively. not want do. 1 example: col1 = 0, 0, 0.2, 0.2, 0, 0, 0, 0, 0, 0.2, 0.2, 0.2, 0, 0.2, 0, 0.2; result_col1= 0.4 1.0; in example, after first 2 0.2 there 5 0 consecutively (the rule stop), script add these 2 values. then, script continue , found 0.2 spaced less 5 0 consecutive add values. thanks.
t = importdata('data.xls') t= t.sheet1; % expect mxn matrix d = cumsum(t); % adds values consecutively [m,n] = size(t) ii = 1:n tmp = unique(d(:,ii)); % extracts unique values of cumsum tmp2 = [tmp(1) diff(tmp)]; % returns actual sum wanted result{ii} = tmp2; % save in cell, since not tmp2s same length end
how add stopping condition based on 5 or more consecutive zeros i'm not sure yet.
Comments
Post a Comment