我想在一个图中绘制r1
和r2
的值,我该怎么做?
for i=1:10
r1=rand(1)
r2=max(rand(1,2))
end
感谢您的帮助!
答案 0 :(得分:2)
有许多方法,这里有几个选项:
clc;
clear all, close all;
r1 = zeros(10, 1);
r2 = zeros(10, 1);
x = 1:10;
for i=1:10
r1(i) = rand(1);
r2(i) = max(rand(1,2));
end
figure('Name', 'Values of r1 and r2', 'NumberTitle', 'off');
hold on;
axis([0, 11, -0.5, 1.5])
plot(x, r1, '+', x, r2,'o'); %many possibilities and options here for line style
h = legend('r1', 'r2');
xlabel('index')
ylabel('value')
disp('press a key');
pause();
close all;
答案 1 :(得分:1)
for i=1:10
r1(i)=rand(1)
r2(i)=max(rand(1,2))
end
plot(r1)
hold on
plot (r2)