I have data in a matrix generated in a nested for loop. I want to only plot the data that meets a certain condition (e.g. it must be bigger than 0.6
). Whether or not the data point meets that condition is stored as 1
or 0
in my mlist
matrix.
What is the easiest way to plot this in Matlab? For the data points that don't meet the condition, it can just be white space.
xlist = linspace(-1,1,20);
ylist = linspace(-2,2,30);
zlist = zeros(length(xlist),length(ylist));
mlist = zeros(length(xlist),length(ylist));
% iteration counter
ii = 0;
jj = 0;
for x = xlist
ii = ii + 1;
for y = ylist
z = sin(x*y);
jj = jj + 1;
zlist(jj) = z;
if z > 0.6
mlist(jj) = 1;
else
mlist(jj) = 0;
end
end
end
contourf(ylist,xlist,zlist)
mesh(ylist,xlist,zlist)