Include missing elements in array (matlab)
显示 更早的评论
I have a Matlab table called 'mytable' with two columns (Times and value). See example extract below:

I would like to detect and include the missing time stamps in the Times column and assign an empty value in the following way:

I have only figured out how to do it using the following code:
%%Creates a complete duration array
A=duration(00,00,00);
B=duration(23,59,59);
Complete_time_array=linspace(A,B,86400);
%%Compare Complete_time_array with mytable.Times values and include the missing time stamps
Times=repmat({''},length(Complete_time_array),1);
value=repmat({''},length(Complete_time_array),1);
for t=1:length(Complete_time_array)
if any(strcmp(char(Complete_time_array(1,t)),mytable.Times))==1
index=find(strcmp(char(Complete_time_array(1,t)),mytable.Times));
Times{t,1}=mytable.Times(index,1);
value{t,1}=mytable.value{index,1};
else
Times{t,1}=char(Complete_time_array(1,t));
value{t,1}='';
end
end
mynewtable=table(Times,value);
However, when working with tables that have thousands of rows, this code takes too long despite having used the 'any' and 'find' matlab functions. Does anybody know how to achieve this goal more efficiently?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!