Remove matrix from cell array that doesn't fit required matrix size
1 回表示 (過去 30 日間)
古いコメントを表示
Hello. I am trying to make a cell array which splits the data into sets of 20 days. This nearly works but for the last set which is DataE20(14) I get a 4x2 array instead of the wanted 4x20. Is there any way to remove this to only get 4x20?
data =readtable('EURUSD=X.csv')
Open = data(:,2);
High= data(:,3);
Low = data(:,4);
Close = data(:,5);
%Store the data Open,High, Low and Close for every 20 days in the variable
%DataE20
G = floor((0:height(data)-1)/20).' + 1;
DataE20 = splitapply(@(Date,Open,High,Low,Close,AdjClose,Volume) {[Open,High,Low,Close].'}, data, G)
celldisp(DataE20(14))
Any help would be greatly appreciated. Thank you.
0 件のコメント
採用された回答
Mathieu NOE
2022 年 12 月 1 日
hello
this will remove the unwanted trailing data
data =readtable('EURUSD=X.csv')
[m,n] = size(data);
k = floor(m/20)*20; % gives me exact number of rows of data for 20 days period
data = data(1:k,:); % removes extra unwanted trailing data
Open = data(:,2);
High= data(:,3);
Low = data(:,4);
Close = data(:,5);
%Store the data Open,High, Low and Close for every 20 days in the variable
%DataE20
G = floor((0:height(data)-1)/20).' + 1;
DataE20 = splitapply(@(Date,Open,High,Low,Close,AdjClose,Volume) {[Open,High,Low,Close].'}, data, G)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!