% Any1 Can Plot This data Values by using Contour3 Plot Command of Matlab. x_lower=-100; x_upper=100; y_lower=-100; y_upper=100; Number_of_x_Steps=400; Number_of_y_Steps=400; dx=(x_upper-x_lower)/Number_of_x_Steps; dy=(y_upper-y_lower)/Number_of_y_Steps; for j=1:Number_of_y_Steps for i=1:Number_of_x_Steps ds=dx*dy; x=x_lower+1*dx+(i-1)*dx; y=y_lower+1*dy+(j-1)*dy; end end
I am guessing you want to contour plot the x or y variable? The way that the for loops are set up this won't be possible. Since the x and y variable aren't indexed for each iteration of the loop, they will override themselves. Thus once the loop finishes, x and y are just constants. To do a contour plot, your plotting variable needs to be a matrix. For example, I re-wrote the inside of the loop to create the matrix "out". Notice that the indexes of "out" are defined for every iteration of i and j, out(i,j). The result is the matrix "out" is a 400x400 matrix. Then the "contour3(out,40)" creates a contour plot of "out" with 40 contours. for j=1:Number_of_y_Steps for i=1:Number_of_x_Steps out(i,j) = sin(0.02*i)+cos(0.02*j); end end contour3(out,40) On a side note, consider pre-allocating variables that grow under loops; it will speed up the calculations. Also consider vectorizing for loops; Matlab is much faster at vectorized calculations than iterations.
Join our real-time social learning platform and learn together with your friends!