Question

This Matlab code here is supposed to plot the values stored in the vector X and Y which are already filled by the user, the problem here is : when you click on complex and real poles, the plotting results the right points, while when entering only real poles, the output is weird. It's like the x-axis is on the y-axis, and I don't know what is exactly on the horizontal axis.

axis([-10,10,-10,10])
grid
[x,y] = ginput 

subplot(2,2,1)
axis([-10,10,-10,10])
grid

subplot(2,2,2)
axis([-10,10,-10,10])
hold all
grid


x = round (x)
y = round (y)

if( y > 0.5 | y < 0.5)
r1 = x + i*y
r2 = conj(r1)

plot (r1,'*')
hold all 
plot (r2,'*')

else

plot (x,y)

end
Was it helpful?

Solution

I'm not 100% sure what you are saying, but I believe you problem is in the if statement as shown below. Specifically, you can never enter the first clause unless y=.5, which is unlikely. I suspect you wanted abs(y)<0.5, to look between [-0.5 0.5]. Secondly, your two plots don't match each other, the first plots complex numbers, and the second x and y values. That just doesn't seem right, but I'm not certain what you are trying to do, so I don't know how to fix it.

if( y > 0.5 | y < 0.5)

    r1 = x + i*y
    r2 = conj(r1)

    plot (r1,'*')
    hold all 
    plot (r2,'*')

else

    plot (x,y)

end

OTHER TIPS

The problem was that the Y should be in this range : if ( y > 0.5 | y < -0.5 ) I by mistake wrote it : if ( y > 0.5 | y < 0.5 )

and why I want this range, because I have the Y-axis representing the Imaginary axis, and the X-axis representing the Real axis, whenever I attempt to enter a Real number, the y coordinate always has a value for example y = 0.001, meaning it's never equal to zero, that's why I needed this approximation to assure that if Y's value is larger than 0.5 or smaller than -0.5 then it's a complex number, otherwise it's real.

And finally, I used : scatter (x,y,'filled') instead of plot cause plot drew a line, not points.

thanks for everyone :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top