1

I have a structured array (1x1) called 'Data' which has 3 fields. Each field contains a vector of data.

The following code is used to replace values which vary by greater than 0.2 with the value next to it with NaN. However, is it possible to alter this code so that the value which alters by 0.2 does not change to NaN but changes to the value which it was compared to?

for i=1:3;
    I{i} = find(diff(Data.(Names{i}))>0.2); 
    Data.(Names{i})(I{i}+1)=NaN;
end

thanks

Jon Egerton
  • 40,401
  • 11
  • 97
  • 129
user1053544
  • 107
  • 4
  • 11

1 Answers1

1

If I understand you correctly you are comparing an element with the previous element. If the difference is greater than 0.2 then replace this element with the previous one?

Then you're almost there. Assign the value of the previous elements like this:

Data.(Names{i})(I{i}+1)=Data.(Names{i})(I{i})
John
  • 480
  • 2
  • 9