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 view (last 30 days)
Show older comments
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
Answers (1)
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!