문제

I would want to graph the values of r1 and r2 in one plot, how can I do it?

for i=1:10
r1=rand(1)
r2=max(rand(1,2))
end

Thank you for your help!

도움이 되었습니까?

해결책

There are many, many ways, here is one that exposes a few options:

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;

다른 팁

for i=1:10
r1(i)=rand(1)
r2(i)=max(rand(1,2))
end
plot(r1)
hold on 
plot (r2)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top