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 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!