I am trying to use a combination of if and for statements to find and replace certain cells in my matrix with NaN.
My goal for this code is to develop an algorithm that looks through my final vector (in this case p4) and replaced all values in p4 with Nan when the percent difference between p1 and p2 (calculated in percdif) is greater than 10%. However, I want it to skip every cell where p4 is less than 20.
Here is my current code
p1=[11 15 7 40 50 100];
p2=[8 14 6 38 35 95];
This was my attempt:
for i = 1:size(cp1,1)
this gives the result:
cp1=[NaN 14.5 6.5 39.0 42.5 97.5]
My intended result was
cp1=[9.5 14.5 6.5 39 NaN 97.5]
What do I need to change in my for and if loops to be able to get this result?