What is the best way to make bodemag of multiple MIMO systems distinguishable? Markers?

2 views (last 30 days)
So I have few LTI models whoose response looks something like this:
rng(200,'twister')
sys1 = rss(8,2,2);
[sys2,~] = balred(sys1,2,'StateProjection','truncate');
sys3 = sys2*makeweight(1,[1e3,db2mag(-10)],db2mag(-40));
bodemag(sys1,'k',sys2,'-.r',sys3,'--b',{1e1,1e5})
Where two systems have basically the same response, while the third system rolls off away from them at higher frequencies. A code example should reproduce this:
Now, I need a way to make such a figure B/W printer friendly (for some scientific article) and for the reader to be able to clearly distinguish between those systems and in specific frequency range (i.e {1e1,1e5}). Only way seems to be using the markers, but as far as I've tried, this part of MATLAB seems to be limited in combination with bodemag (and my existing knowledge of plotting figures).
I have tried to plot the response for all three systems without markers (i.e the image above), then hold on, then add markers for two overlapping systems with unequally distant points (i.e no overlapping of points) but without success.
[EDIT] Below is one of the examples I'm dealing with (the minimum code to replicate would be too long without saving all the variables and sharing that way). Here, for two out of four systems, I have added '--bd' and '-.rx'. Which makes this figure look horrible... Not to mention that the third out of four (solid green) is nowhere to be seen.
Any help would come great - even if there is a way to do it without markers.
Cheers all,
Bruno

Accepted Answer

Paul
Paul on 18 Apr 2022
Here's some code to put an 'o' marker on every 10th data point. Adapt as needed to change markers, line styles, line colors, maker spacing, etc.
rng(200,'twister')
sys1 = rss(8,2,2);
[sys2,~] = balred(sys1,2,'StateProjection','truncate');
sys3 = sys2*makeweight(1,[1e3,db2mag(-10)],db2mag(-40));
bodemag(sys1,'k',sys2,'-.r',sys3,'--b',{1e1,1e5})
hax = get(gcf,'Children');
for ii = 1:numel(hax)
if strcmp(hax(ii).Type,'axes')
hc = hax(ii).Children;
for jj = 1:numel(hc)
if strcmp(hc(jj).Type,'hggroup')
% all Line poperties accessible here
% set Marker and space ever 10th data point
hc(jj).Children.Marker = 'o';
hc(jj).Children.MarkerIndices = 1:10:numel(hc(jj).Children.MarkerIndices);
end
end
end
end
  3 Comments
Bruno Dogancic
Bruno Dogancic on 18 Apr 2022
For anyone who is in the same boat as I'm that might want to offset the markers and perhaps start at different point to completely avoid merkers overlapping, here is a simple (and not the most elegant) edit to @Paul's answer
%% Modified answer
rng(200,'twister')
sys1 = rss(8,2,2);
[sys2,~] = balred(sys1,2,'StateProjection','truncate');
sys3 = sys2*makeweight(1,[1e3,db2mag(-10)],db2mag(-40));
bodemag(sys1,'k',sys2,'-.r',sys3,'--b',{1e1,1e5})
hax = get(gcf,'Children');
for ii = 1:numel(hax)
if strcmp(hax(ii).Type,'axes')
hc = hax(ii).Children;
for jj = 1:numel(hc)
if strcmp(hc(jj).Type,'hggroup')
if jj == 1 % for the first line use 'o'
% all Line poperties accessible here
% set Marker and space every 10th data point, start at 1
hc(jj).Children.Marker = 'o';
hc(jj).Children.MarkerIndices = 1:10:numel(hc(jj).Children.MarkerIndices);
end
if jj == 2 % for the second line use 'x'
% all Line poperties accessible here
% set Marker and space every 11th data point, start at 2
hc(jj).Children.Marker = 'x';
hc(jj).Children.MarkerIndices = 2:11:numel(hc(jj).Children.MarkerIndices);
end
if jj == 3 % for the third line use 'd'
% all Line poperties accessible here
% set Marker and space every 12th data point, start at 3
hc(jj).Children.Marker = 'd';
hc(jj).Children.MarkerIndices = 3:12:numel(hc(jj).Children.MarkerIndices);
end
end
end
end
end
This would produce an image like:
Which look exactly as I have imagined but now the legend is missing the markers. @Paul, any way to add markers to the line it belongs to in a legend (besides a slight after processing of the image in Inkscape/Paint)? :)
Paul
Paul on 18 Apr 2022
For reasons that I don't understand, putting the Marker in the LineSpec arguments to bodemag seems to do the trick.
Unfortunately, a lot of the graphics in the Control System Toolbox aren't defined at all in the doc (AFAICT), so one has to sleuth around and experiment.
%% Modified answer
rng(200,'twister')
sys1 = rss(8,2,2);
[sys2,~] = balred(sys1,2,'StateProjection','truncate');
sys3 = sys2*makeweight(1,[1e3,db2mag(-10)],db2mag(-40));
bodemag(sys1,'-ko',sys2,'-.rx',sys3,'--bd',{1e1,1e5}) % added the - for sys1 also
hax = get(gcf,'Children');
for ii = 1:numel(hax)
if strcmp(hax(ii).Type,'axes')
hc = hax(ii).Children;
for jj = 1:numel(hc)
if strcmp(hc(jj).Type,'hggroup')
if jj == 1 % for the first line use 'o'
% all Line poperties accessible here
% set Marker and space every 10th data point, start at 1
%hc(jj).Children.Marker = 'o';
hc(jj).Children.MarkerIndices = 1:10:numel(hc(jj).Children.MarkerIndices);
end
if jj == 2 % for the second line use 'x'
% all Line poperties accessible here
% set Marker and space every 11th data point, start at 2
%hc(jj).Children.Marker = 'x';
hc(jj).Children.MarkerIndices = 2:11:numel(hc(jj).Children.MarkerIndices);
end
if jj == 3 % for the third line use 'd'
% all Line poperties accessible here
% set Marker and space every 12th data point, start at 3
%hc(jj).Children.Marker = 'd';
hc(jj).Children.MarkerIndices = 3:12:numel(hc(jj).Children.MarkerIndices);
end
end
end
end
end
legend

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!