divide a matrix based on the presence of a coefficient
조회 수: 4 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Chunru
2021년 4월 23일
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
Chunru
2021년 4월 26일
(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
2021년 4월 23일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Preprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!