1
votes

I am plotting a closed loop poles of a systems using pzmap.m or pzplot.m whichever you prefer. I want to see the movement of poles and zeros as I change a variable depicted by L.

The function does not have a direct handle for color. In the example you can just choose the standard colors but cannot give your own color. Since I have to plot multiple times on the same figure, I create a handle for every iteration in a for loop and use findobj to set the color of the curve. To get the colors I want to have a colorbar. So I use jet to get the color distribution for my graph. But the market size stays the same and I have one ugly looking figure.

MWE:

cb=jet(10);
s=tf('s');
L_array=5:5:50;

figure; hold on;
for i=1:length(L_array)
    L=L_array(i);
    G=((58.2+11.7*L)*s^2*25^2+(3996.8 + 815.7*L)*s*25+815.7*25^2)/(s^2*(s^2*25^2+126.9*s*25+(3996.8+1.9*25^2)));
    CL=feedback(G,1);
    pzmap(CL);
    h = findobj(gcf,'type','point'); set(h,'markers',12,'color',cb(i,:));
    clear L G CL h
end
grid;
c=colorbar
c.Label.String = 'L'

If you run it you'll see that the size doesn't change and graph looks crazy with the y axis on either side labelled with ticks. I want a proper colorbar from blue to red and the colors distributed properly but can't get it after multiple tries. If I can get less cluttering that would be helpful too.

1
I have run your code: If I don't understand wrong, you just want to color the "time", so each time you plot something it will have some different color. What I can see in my computer (Matlab 2014b) is that the line h=findobj(... actually has no effect, and that is your problem. h is empty. - Ander Biguri
Yeah I figured that out...but I cannot understand for the life of me what property name to use. Using 'type' 'point' returns empty. If I use h=findobj(gcf,'marker', 'o') or h=findobj('marker','x') then I have something but setting the command set(h,'MarkerSize',12,'MarkerEdgeColor',=cb(i,:)) makes everything of the same color...I know its a problem of handle but cant figure it out - Zero
I am writing a response now, I got it. - Ander Biguri
kudos :) thanks for the effort man...cheers - Zero
check my answer, and consider accpeting it if it helped ;) - Ander Biguri

1 Answers

1
votes

The are several problems in your code

  • h = findobj(gcf,'type','point'); The things drawn in the screen are actually of type 'line'!
  • Every iteration, you catch all the points, modify them an dimdediately after delete the properties with clear.

Additionally, h = findobj(gcf,'type','line'); will not return a single thing, but a set of them, so you need to index through it to set the properties. My modified code working looks like this:

clear;clc
cb=parula(10);
s=tf('s');
L_array=5:5:50;

figure; hold on;
for i=1:length(L_array)
    L=L_array(i);
    G=((58.2+11.7*L)*s^2*25^2+(3996.8 + 815.7*L)*s*25+815.7*25^2)/(s^2*(s^2*25^2+126.9*s*25+(3996.8+1.9*25^2)));
    CL=feedback(G,1);
    pzmap(CL);

end

% lets do this in the end!

% you will have length(L_array)*2 +1 items in h
 h = findobj(gca,'type','line'); 
for jj=2:length(h)
        set(h(jj),'MarkerSize',12,'Color',cb(floor(jj/2),:));
end
grid;

colormap(parula);   % I am using parula, you can use jet, but I discourage it
c=colorbar;

enter image description here

PD: there are tons of reasons not to use jet!! Use perceptually uniform colormaps please!