Write a 'for' loop from 1 to 3 using 'i' as the variable. For each value of 'i', create a vector 'x' and vector 't' to plot.
17 ビュー (過去 30 日間)
古いコメントを表示
Write a 'for' loop from 1 to 3 using 'i' as the variable. For each value of 'i': Create a vector 'x' of 10 random numbers between 0 and 1. Create a second vector 't' which is equal to ten integers from 1 to 10. Plot 'x' versus 't' in figure 1. Use 'hold on' to keep each plot. Use a different color for the line for each value of 'i'. At the very end, add the text 'time' using 'xlabel' to the horizontal axis, and the text 'f(t)' using 'ylabel' to the vertical axis. This is what I have so far:
% Creating a 'for' loop from 1 to 3 using 'i' as the variable
for i=1:3
% For each value of 'i', creating a vector 'x' of 10 random numbers between 0 and 1
x=rand(1,10);
% For each value of 'i', creating a second vector 't' which is equal to 10 integers from 1 to 10
t=randi([1,10],10);
end
% Plotting 'x' versus 't' in figure 1
figure(1),plot(x,t)
% Using 'hold on' to keep each plot
hold on
% Using a different color for the line for each value of 'i'
%add code
% Adding the text 'time' using 'xlabel' to the horizontal axis
xlabel('time')
% Adding the text 'f(t)' using 'ylabel' to the vertical axis
ylabel('f(t)')
0 件のコメント
回答 (1 件)
James Tursa
2018 年 3 月 5 日
Move the plotting and "hold on" inside the loop. For the t vector, the instructions did not say "random", so probably what was meant was just t = 1:10. And finally, since the xlabel is time and the ylabel is f(t), you should be using plot(t,x) instead of plot(x,t).
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!