Remove matrix from cell array that doesn't fit required matrix size
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Mathieu NOE
on 1 Dec 2022
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 Comments
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!