How to extract data from different strata?
조회 수: 2 (최근 30일)
이전 댓글 표시
I want to extract the data from the perticular strata, but the problem is i have to do it manually, and that is very time consuming. I want to create a code which can extract the data easily. I have attached the excel file of dataset for reference.
Ex: In the attached file, you see there are different data in the columns provided along with the strata number. Now, i have to read the in matlab for further process, like i want to separate the data of all the strata.
Say: Strata 1 has one row of data, but strata 3 has two rows of data. So, if i recall the data from strata 3, it will read the whole data of strata 3.
댓글 수: 0
채택된 답변
Sarvesh Kale
2023년 2월 7일
편집: Sarvesh Kale
2023년 2월 7일
I understand that you want data grouped by same Strata number in your spreadsheet, here is my attempt
T = readtable('Dataset.xlsx',"ReadRowNames",1);
n = length(T.Strata)
for i=1:n
if isnan(T.Strata(i))
T.Strata(i) = T.Strata(i-1); % replace the NaN with previous Strata Values, maybe not the best method
end
end
T(T.Strata==3,1:end-1)
% the above line says select only those rows where Strata is 3 and all
% columns except the Strata which is represented by end-1
% you can replace T.Strata == 33 and it will give you all those which have
% Strata equal to 33
You can find more information on the readtable function in the following documentation
I hope the provided solution helps you ! please accept the answer if it does. Thank you
댓글 수: 3
Sarvesh Kale
2023년 2월 7일
I do not have information on it Rahul Verma, you might head to wikipedia page on stratified sampling and see if that helps !
추가 답변 (1개)
Voss
2023년 2월 7일
data = xlsread('Dataset.xlsx')
data(:,end) = fillmissing(data(:,end),'previous');
stratadata = splitapply(@(x){x},data(:,1:end-1),findgroups(data(:,end)))
Now stratadata is a cell array with each cell containing one stratum of data. To access a particular stratum's data, use curly braces, e.g.:
stratadata{3} % data for 3rd stratum
stratadata{13} % data for 13th stratum
참고 항목
카테고리
Help Center 및 File Exchange에서 Special Values에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!