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!