How to extract data from different strata?

조회 수: 2 (최근 30일)
Rahul Verma
Rahul Verma 2023년 2월 7일
댓글: Rahul Verma 2023년 4월 27일
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.

채택된 답변

Sarvesh Kale
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
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 !
Rahul Verma
Rahul Verma 2023년 4월 27일
Hellos sir,
I have one more question. I have to calculate one parameter whose formula is given below:
x= N1 * S1
Where N1 is the number of elements in respective strata and S is the stadard deviation of respective strata.
I have to create one loop, in which both the variables gets its values respectively.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Voss
Voss 2023년 2월 7일
data = xlsread('Dataset.xlsx')
data = 67×9
0.3509 0.3546 0.2230 0.0912 0.8921 0.4104 0 0.5590 1.0000 0.6000 0.6950 0.4833 0.3298 0 0.2010 0.8526 0.6135 2.0000 0.4717 0.5284 0.3234 0.2842 0.8456 0.7677 1.0000 0.6040 3.0000 0.5321 0.4610 0.2007 0.2667 0.7735 0.8484 0.8034 0.7770 NaN 0.7962 0.7908 0.5725 0.5088 0.3012 0.3760 0.2555 0.4314 4.0000 0.6566 0.6525 0.5762 0.5228 0.3396 0.4718 0.2381 0.4391 NaN 0.5887 0.5248 0.6989 0.8105 0.7283 0.6395 0.3467 0.5277 5.0000 0.5132 0.4362 0.5130 0.6807 0.8232 0.4460 0.4993 0.7802 6.0000 0.5019 0.4823 0.4387 0.4737 0.9364 0.4497 0.5068 0.7189 NaN 0.7623 0.7340 0.5799 0.4561 0.2542 0.6603 0.4572 0.2838 7.0000
data(:,end) = fillmissing(data(:,end),'previous');
stratadata = splitapply(@(x){x},data(:,1:end-1),findgroups(data(:,end)))
stratadata = 38×1 cell array
{[ 0.3509 0.3546 0.2230 0.0912 0.8921 0.4104 0 0.5590]} {[ 0.6000 0.6950 0.4833 0.3298 0 0.2010 0.8526 0.6135]} {2×8 double } {2×8 double } {[0.5887 0.5248 0.6989 0.8105 0.7283 0.6395 0.3467 0.5277]} {2×8 double } {2×8 double } {[ 0.1887 0.2305 0.0967 0 0.3766 0.2877 0.5297 0.6916]} {[ 0.1170 0 0 0.0421 0.6762 0.5055 0.4171 0.9155]} {2×8 double } {2×8 double } {[ 0.7774 0.9326 0.8810 1 0.6023 0.5257 0.4885 0.6921]} {3×8 double } {2×8 double } {2×8 double } {[0.2679 0.3191 0.2082 0.2175 0.1297 0.3414 0.4634 0.5999]}
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
ans = 2×8
0.4717 0.5284 0.3234 0.2842 0.8456 0.7677 1.0000 0.6040 0.5321 0.4610 0.2007 0.2667 0.7735 0.8484 0.8034 0.7770
stratadata{13} % data for 13th stratum
ans = 3×8
0.2717 0.3085 0.1859 0.4561 0.4884 0.4996 0.4701 0.7375 0.4264 0.3830 0.2342 0.2456 0.5006 0.4845 0.4984 0.7579 0.4302 0.4326 0.3532 0.2947 0.3437 0.4980 0.6221 0.7611
  댓글 수: 2
Rahul Verma
Rahul Verma 2023년 2월 7일
While running this, data(:,end) = fillmissing(data(:,end),'previous');
i face one prblem. Its showing " Undefined function or variable 'fillmissing'".
Rahul Verma
Rahul Verma 2023년 2월 7일
I am using Matlab R2015a, which is older version. Thats why the written syntax may not be worked. But thanks, i will use your written syntax in the newer version.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by