divide a matrix based on the presence of a coefficient
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi everyone, I need a hand.
I have 87600 x 4 matrices where, in the fourth column, there is a value that differentiates between holidays = 0.8, pre-holidays = 0.9 and working days = 1.
How is it possible to create a script that allows you to divide the starting matrix into three matrices?
Where a matrix contains all the rows to which the fourth column is associated with the index 0.8, the second matrix contains all the rows in which the fourth column is associated with the index 0.9 and the third all the rows in which the last column is associated with a 1.
I hope I was clear in the question, an infinite thanks to those who know how to help me.
2 Kommentare
Antworten (2)
Chunru
am 23 Apr. 2021
A = randi(5, [80, 4]); % your data
u = unique(A(:, 4)); % unique values of column 4
for i=1:length(u)
B{i,1} = A( A(:,4) == u(i), :);
end
B
2 Kommentare
Chunru
am 26 Apr. 2021
(1) Change the first line to your own data. I am using some random generated data for testing.
(2) Line 2 find the unique values of column 4
(3) The rest of code groups the matrix according to value in column 4 and assign the reults into a cell array.
Steven Lord
am 23 Apr. 2021
Do you need these as separate variables or do you just need to process each group of dates separately? In the latter case, see the findgroups, splitapply, groupsummary, and grouptransform functions and the functions listed in the "See Also" sections on their documentation pages.
Creating three variables from an array is probably okay, but creating a dynamic number of variables (when or if you start separating US holidays from UK holidays from state holidays from ...) is straying into discouraged territory.
Siehe auch
Kategorien
Mehr zu Data Preprocessing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!