i am trying to insert zeroes in an array based on a condition. When i try to do it. It doesn't insert in the right index. Can anyone help me with this?
1 次查看(过去 30 天)
显示 更早的评论
I have a 1 Hz table with timestamps and number. This table has NaNs. When i removed NaNs from the number column. My difference (duration) in time is now 1 seconds, 30 seconds, 50 seconds and so on. I want to insert zeroes to number column where the duration is more than 20 seconds.the zeroes should be equal to the seconds of the duration because eventually it's a 1 second data. I am trying the following code. But, it doesn't work as it is inserting 0s in wrong index. Since, the new array size is increased now. It's inserting 0s in a wrong index. How do i format the array index to insert my 0s?
for i=1:size(duration,1)
if duration(i)>15
rowToInsert = i; %change here It inserts in a wrong place. How do i change rows to insert based on the new input_array
rowVectorToInsert = zeros(duration(i)-1,1);
input_array = [input_array(1:rowToInsert-1,:); rowVectorToInsert; input_array(rowToInsert:end,:)];
end
end
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!