Question

MATLAB - adding vectors randomly inside another vector How do you add random vectors inside another...

MATLAB - adding vectors randomly inside another vector

How do you add random vectors inside another vector without changing the size? I am looking for it to be both vertical and horizontal, without adding any rows or columns.

Say I want to add [6, 6, 6, 6, 6, 6] into a large vector of zeros that is 10x10. How would I do so? Both horizontally and vertically?

I want to place the [6,6,6,6,6,6] vector inside of a vector of 10x10 zeroes. I want it so the program does it randomly. I want it so it doesnt change the size of the 10x10 zero vector. I have made a code that does so already but sometimes changes the dimensions of the 10x10 zero vector.

play_board = zeros(10);

row1 = randi(size(play_board, 1),1,1);
col1 = randi(size(play_board, 2),1,1);
direction = randi(2, 1, 1); % 1 for vertical, 2 for horizontal.

row2 = row1 + length(submarine) - 1;
col2 = col1;
play_board(row1:row2, col1) = submarine(1);

But occasionally this changes the dimnesions of play_board. I want play_board to remain 10x10 with the [6,6,6,6,6,6] vector inside

Just a note submarine is submarine = [3, 3, 3]
0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
MATLAB - adding vectors randomly inside another vector How do you add random vectors inside another...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Add another changeColor() method (i.e. you will now have 2 methods called "changeColor"). This one accepts...

    Add another changeColor() method (i.e. you will now have 2 methods called "changeColor"). This one accepts an int parameter and changes the color based on that int. The valid colors are "red", "yellow", "green", "blue", "magenta" and "black". In your code, map each color to an integer (e.g. in my code 3 means green.) If the number passed to the method is not valid, change the color to red. In the bounceTheBall() method, where you test for collisions with top...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT