Write a for loop from 1 to 3 using i as the variable. For each value...

70.2K

Verified Solution

Question

Electrical Engineering

Write a for loop from 1 to 3 usingi as the variable. For each value ofi:

Create a vector x of 10 random numbers between0 and 1. Create a second vector t which is equal to ten integersfrom 1 to 10. Plot x versus t infigure 1. Use hold on to keep each plot. Use adifferent color for the line for each value ofi.

At the very end, add the text 'time' usingxlabel to the horizontal axis, and the text'f(t)' using ylabel to thevertical axis.

This is what I have so far:

% Creating a 'for' loop from 1 to 3 using 'i' as thevariable
for i=1:3
% For each value of 'i', creating a vector 'x' of 10 random numbersbetween 0 and 1
x=rand(1,10);
% For each value of 'i', creating a second vector 't' which isequal 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 horizontalaxis
xlabel('time')

% Adding the text 'f(t)' using 'ylabel' to the verticalaxis
ylabel('f(t)')

Answer & Explanation Solved by verified expert
4.3 Ratings (810 Votes)
You have already done the code completely except a smallmisunderstanding When they say Create a second vector t which isequal to ten integers from 1 to 10 it means that just createintegers 1 2 3 10 not random    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students