Remove matrix from cell array that doesn't fit required matrix size
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Killian Flynn
le 1 Déc 2022
Réponse apportée : Mathieu NOE
le 1 Déc 2022
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 commentaires
Réponse acceptée
Mathieu NOE
le 1 Déc 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!