converting a minute chart

1 回表示 (過去 30 日間)
AA
AA 2014 年 10 月 11 日
編集済み: AA 2014 年 11 月 27 日
Hi guys, i have a table with 6 columns and 4 million rows. Column1 shows the date and column 2 the time. Column 3 the opening price, column4 the max price, column5 the min price and column6 the closing price. The whole table presents a one minute chart. I want to convert this to a two minute chart in the following manner: two rows have to be combined(row1 and row2). Column 1,2,3 should have the values of row1. Column4 should contain the max value of row1 and row2. Column 5 should have the min value of row1 and row2. Column6 should have theclosing value of row2.

採用された回答

Andrei Bobrov
Andrei Bobrov 2014 年 10 月 11 日
編集済み: Andrei Bobrov 2014 年 10 月 11 日
x - your array (4e6 x 6)
n = ceil((1:size(x,1))'/2);
out = [x(1:2:end,1:3), accumarray(n,x(:,4),[],@min),...
accumarray(n,x(:,5),[],@max),x(2:2:end,6)];
n = 2:100;
for jj = numel(n):-1:1
n1 = ceil((1:size(x,1))'/n(jj));
out{jj} = [x(1:n(jj):end,1:3), accumarray(n1,x(:,4),[],@min),...
accumarray(n1,x(:,5),[],@max),x(n(jj)-1:n(jj):end,6)];
end
  2 件のコメント
AA
AA 2014 年 10 月 29 日
i get the following error:
out = [out(1:2:end,1:3), accumarray(n,out(:,4),[],@min),...
accumarray(n,out(:,5),[],@max),out(2:2:end,6)]
Undefined function 'accumarray' for input arguments of type 'table'.
AA
AA 2014 年 11 月 9 日
編集済み: AA 2014 年 11 月 27 日
n = 2:100;
for jj = numel(n):-1:1
n1 = ceil((1:size(x,1))'/n(jj));
out{jj} = [x(1:n(jj):end,1:3), accumarray(n1,x(:,4),[],@min),...
accumarray(n1,x(:,5),[],@max),x(1:n(jj):end,6)];
end

サインインしてコメントする。

その他の回答 (1 件)

SK
SK 2014 年 10 月 11 日
編集済み: SK 2014 年 10 月 11 日
N = 4000000;
C = reshape(Table(:, 4), [2,N/2]);
Cmax = transpose(max(C, 1));
C = reshape(Table(:, 5), [2,N/2]);
Cmin = transpose(min(C, 1));
TableNew = [ Table(1:2:N, 1:3), Cmax, Cmin, Table(2:2:N, 6) ];
Edited to correct an error.
  11 件のコメント
SK
SK 2014 年 11 月 1 日
編集済み: SK 2014 年 11 月 1 日
But C should be a matrix not a cell.
function TableNew = MakeNewTable(Table, m)
N = size(Table, 1);
N = N - rem(N,m);
Table = Table(1:N, :);
C = reshape(Table(:, 4), [m,N/m]);
Cmax = transpose(max(C, 1));
C = reshape(Table(:, 5), [m,N/m]);
Cmin = transpose(min(C, 1));
TableNew = [ Table(1:m:end, 1:3), Cmax, Cmin, Table(m:m:end, 6) ];
end
% Insert code here to convert Table from table type object to matrix.
NewTable = cell(99,1);
for m = 2 : 100
NewTable{m-1} = MakeNewTable(Table, m);
% Insert code here to convert NewTable{m-1} from matrix to table type.
end
AA
AA 2014 年 11 月 3 日
thanks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by