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.

采纳的回答

Mathieu NOE
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 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by