我在Simulink中有多路复用器块Mux的范围(我想在一个图中绘制多个wavaforms)。模拟后我需要以定义的形式(背景颜色,线宽等)将其导出到eps / pdf和png文件。
实际问题:
我的梦想:
最终状态是实现我的梦想。
我的档案:
% Get the data from Simulink
% First column is the time signal
% in Scope in Simulink : Array with time
[nothing, NumOfSgns] = size(ScopeData)
time = ScopeData(:,1);
% Plot all signals
hold on
for j=0:NumOfSgns-2,
graph=plot(time,ScopeData(:,2+j:end),'Color', rand(1,3));
% Signals description and position of the legend
legend('firs wave form','next wave form','Location','SouthEast');
end
hold off
谢谢。
答案 0 :(得分:1)
问题是同时使用legend
和hold on
:因为您使用hold on
,所以MATLAB在绘制新图之前不会清除旧图。但它不会存储legend
以前的图表信息。您需要手动执行此操作。
这是一些代码(未经测试,目前无法访问MATLAB):
titles = {'A', 'B', 'C', 'D'};
handles = zeros(1, length(titles));
figure;
hold on;
for i = 1 : length(titles)
handles(i) = plot(1 : 10, rand(1, 10), 'Color', rand(1, 3));
end
legend(handles, titles{:});
所以:将plot
返回的句柄存储在向量中,并将其传递给legend
(循环后需要调用)。