필터 지우기
필터 지우기

Is there any more efficient way to split a table than this

조회 수: 3 (최근 30일)
MA
MA 2021년 10월 18일
댓글: MA 2021년 10월 31일
I am trying to split the table datatable into 3 smaller tables t1, t2 and t3, based on the value of the variable 'solar' in 'datatable'. accoding to three ranges:
(60-120) , (121-170) , (171<).
I did the following and its working fine but the issue is its slow and inifecient so How can I modify it to make it faster?
for ii=1:size(datatable)
if(datatable.solarT(ii)>=60 && datatable.solarT(ii)<=120)
t1(ii,:)=datatable(ii,:);
t11 = rmmissing(t1);
elseif(datatable.solarT(ii)>=121 && datatable.solarT(ii)<=170)
t2(ii,:)=datatable(ii,:);
t22 = rmmissing(t2);
else
t3(ii,:)=datatable(ii,:);
t33 = rmmissing(t3);
end
end
thank you in advance,

채택된 답변

the cyclist
the cyclist 2021년 10월 18일
% Set random seed for reproducibility
rng default
% Make up a table with pretend data
N = 30;
x = rand(N,1);
solar = 200*rand(N,1);
dataTable = table(x,solar);
% Define t1 based on restricted range of table value
t1 = dataTable((dataTable.solar>=60)&(dataTable.solar<=120),:)
t1 = 8×2 table
x solar _______ ______ 0.54688 63.42 0.15761 87.749 0.97059 76.312 0.14189 97.953 0.42176 89.117 0.75774 99.673 0.39223 68.077 0.65548 117.05

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by