How to extract data from different strata?
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Sarvesh Kale
on 7 Feb 2023
Edited: Sarvesh Kale
on 7 Feb 2023
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 Comments
Sarvesh Kale
on 7 Feb 2023
I do not have information on it Rahul Verma, you might head to wikipedia page on stratified sampling and see if that helps !
More Answers (1)
Voss
on 7 Feb 2023
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
See Also
Categories
Find more on Special Values 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!