divide a matrix based on the presence of a coefficient
4 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Chunru
on 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 Comments
Chunru
on 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
on 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.
See Also
Categories
Find more on Data Preprocessing 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!