How to multi-color different models in model array responses?

3 views (last 30 days)
I would like to visualize different responses of different systems in a single plot, using Matlab's control toolbox, and to colorize the various curves so it is easy to differentiate between the different systems.
The response plots are easily created using the control toolbox, e.g. step response (using step), response to an arbitrary input (using lsim), etc.
When using separate model objects for the different systems, It's easy to create multi-color plots, e.g., for a step response:
step(Sys1, 'b', Sys2, 'r')
The command above would give one blue curve and one red cure, if Sys1 and Sys2 are each a single system model.
However, if plotting a model array, there's no way to differentiate between the various curves that belong to the same array. E.g.: step(SysArray, 'b') would make all curves blue. step(Sys,'b','r') is invalid - so no easy way to specify various colors. Also, using the "Edit Plot" tool, selecting one curve effectively selects all curves, and any changes to the properties (e.g. line color) would affect all curves.
Is there any way to control the properties of each curve separately?
Thanks in advance!

Accepted Answer

Sagie
Sagie on 28 Jul 2014
A way to perform this is using findobj to get the line handles and set their colors.

More Answers (1)

Craig
Craig on 13 Mar 2014
One option is to plot them using a loop such as:
figure
hold on
Color = {'b','r','g','k'};
sys = rss(2,1,1,4);
for ct = 1:4
stepplot(sys(:,:,ct),Color{ct});
end
  2 Comments
Sagie
Sagie on 23 Mar 2014
Thanks for your answer, and sorry for my late response.
Your code simply plots each single element of the array as a single system model, which avoids my question of handling a model array.
Perhaps my original question is poorly phrased. I'm aware that the models within the array may be accessed separately, before being plotted. The question is whether it is possible to access a single curve representing one of the elements within a model array plot.
Craig
Craig on 24 Mar 2014
There is not a way to treat each line in the system array seperately.
However if you want to toggle the visibility of elements in the array you can achieve that by right clicking the axes and selecting the "Array Selector..." menu item. Also, if you click on a line it will show you in the data tip which element it is.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!