How do i finish the code. I'm not even sure if this is how one would start to run the code

1 次查看(过去 30 天)
Write a program that generates a vector consisting of random integers between 10 and 10 and as soon as a random positive integer that is equal to the last digit of your university ID (9) is found the program stops and displays ONLY the positive even numbers of the vector.
this is what i have so far
v=randi([-10,10])
  2 个评论
Geoff Hayes
Geoff Hayes 2020-5-12
JR - I think that you being asked to continually generate a random integer and that you should be "collecting" these random integers into an array until the code finally generates a 9 (the last digit of your ID). So you will need a loop of some kind (for or while). Start with the loop, collecting the random integers and checking to see if the most recent random number is 9. What would the code look like?

请先登录,再进行评论。

采纳的回答

David Hill
David Hill 2020-5-12
x=randi([-10,10]);
while x(end)~=9;
x=[x,randi([-10,10])];
end
display(x(x>0&mod(x,2)==0));
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by