Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**MATLAB **PLEASE DO NOT DO IF YOU ARE NOT SURE ABOUT YOUR WORK Function Name: battleFormation Inputs: 1. ( double ) 1xN vector of the

**MATLAB

**PLEASE DO NOT DO IF YOU ARE NOT SURE ABOUT YOUR WORK

image text in transcribed

Function Name: battleFormation Inputs: 1. ( double ) 1xN vector of the number of soldiers in each line 2. ( char ) A file name, including extension, for the output file group number File Outputs: 1. A text file showing the soldiers in formations Background: The date is December 21st, 1944. You are Major Hal McCown battalion commander of the U.S. 2nd Battalion. The U.S. has already faced massive casualties in this "Battle of the Bulge." German leader Peiper is on the ropes as his regiment is stretched too thin and his tanks are low on fuel with no reinforcements seeming to be on the way. This is your chance to take them here and win one for the Ol' Red White and Blue and for freedom! You also fancy seeing yourself as a great war hero getting lots of praise back home. This is no time for poor strategy! Lucky for you America has a trick up its star spangled sleeve, MATLAB! Before you charge into battle. You use MATLAB to whip up some tactical battle formations that are sure to win you the war. Function Description: Write a function that that takes in the vector of soldiers in each line and outputs a file showing the soldiers formations. To find the soldiers formations and create the output file, follow these rules: 1. Find the maximum value in the input vector. Each line of the formation will have this many places. 2. For each line of the formation: a. Put the specified number of soldiers from the input vector in the line. For example, if the first number in the vector is 3, there are 3 soldiers in the first line. b. Align the soldiers along the center. If there are 3 soldiers and 5 spaces, there will be one empty space at each end of the line. c. Use a 1 to represent a soldier and a 0 for a vacant position. 3. The output file, given by the second input, should print the lines in the following format: Line has the following line up: a. refers to the current line number, which should start at 1 and increment by 1 for each line, and refers to the soldiers formation. b. There should be two spaces in between the numbers representing the positions. Continued... Homework 8 - Low Level File I/O Example: >> formation([3 5 1], 'formation1.txt') Formation1.txt: 1| Line 1 has the following line up: 0 1 1 1 0 2| Line 2 has the following line up: 1 1 1 1 1 3| Line 3 has the following line up: 0 0 1 0 0 Notes: You are guaranteed that all numbers will be odd. There should not be an empty new line at the end of the file. Hints: Think about how you can find the center of each line and index from there. The zeros() function may be helpful. What happens when you call num2str() on a vector of doubles?

Function Name: battleFormation uts: 1. (double) 1xN vector of the number of soldiers in each line 2. (char) A file name, induding extension, for the output file group number File Outputs: 1. A text fle showing the soldiers in formations Background: The date is December 21st 1944. You are Major Hal McCown battalion commander of the U.S. 2nd Battalion. The US. has already faced massive casualties in this "Battle of the Bulge." German leader Peiper is on the ropes as his regiment is stretched too thin and his tanks are low on fuel with no reinforcements seeming to be on the way. This is your chance to take them here and win one for the Of Red White and Blue and for freedom! You also fancy seeing yourself as a great war hero getting lots of praise back home. This is no time for poor strategy! Lucky for you America has a trick up its star spangled sleeve, MATLAB! Before you charge into battle. You use MATLAB to whip up some tactical battle formations that are sure to win you the war Function Description Write a function that that takes in the vector of soldiers in each line and outputs a file showing the soldiers' formations. To find the soldiers' formations and create the output file follow these rules: 1. Find the maximum value in the input vector. Each line of the formation will have this many places. For each line of the formation: 2. a. Put the specified number of soldiers from the input vector in the line. For example, if the first number in the vector is 3, there are 3 soldiers in the first line Align the soldiers along the center. If there are 3 soldiers and 5 spaces, there will be one empty space at each end of the line. Use a 1 to represent a soldier and a 0 for a vacant position b. c. 3. The output file, given by the second input, should print the lines in the following format: Line cnum> has the following line up: refers to the current line number, which should start at 1 and increment by 1 for each ine, and refers to the soldiers" formation There should be two spaces in between the numbers representing the positions a. b. Continued Homework 8-Low Level File VO Example: >> formation([3 51 formation1.txt') Formation1.txt: 1l Line 1 has the following line up: 1 1 1 e 2l Line 2 has the following line up: 1 111 1 3l Line 3 has the following line up: e 1 e e Notes You are guaranteed that all numbers will be odd. There should not be an empty new line at the end of the file . Hints . Think about how you can find the center of each line and index from there. . The zeros) function may be helpful . What happens when you call num2str) on a vector of doubles? Function Name: battleFormation uts: 1. (double) 1xN vector of the number of soldiers in each line 2. (char) A file name, induding extension, for the output file group number File Outputs: 1. A text fle showing the soldiers in formations Background: The date is December 21st 1944. You are Major Hal McCown battalion commander of the U.S. 2nd Battalion. The US. has already faced massive casualties in this "Battle of the Bulge." German leader Peiper is on the ropes as his regiment is stretched too thin and his tanks are low on fuel with no reinforcements seeming to be on the way. This is your chance to take them here and win one for the Of Red White and Blue and for freedom! You also fancy seeing yourself as a great war hero getting lots of praise back home. This is no time for poor strategy! Lucky for you America has a trick up its star spangled sleeve, MATLAB! Before you charge into battle. You use MATLAB to whip up some tactical battle formations that are sure to win you the war Function Description Write a function that that takes in the vector of soldiers in each line and outputs a file showing the soldiers' formations. To find the soldiers' formations and create the output file follow these rules: 1. Find the maximum value in the input vector. Each line of the formation will have this many places. For each line of the formation: 2. a. Put the specified number of soldiers from the input vector in the line. For example, if the first number in the vector is 3, there are 3 soldiers in the first line Align the soldiers along the center. If there are 3 soldiers and 5 spaces, there will be one empty space at each end of the line. Use a 1 to represent a soldier and a 0 for a vacant position b. c. 3. The output file, given by the second input, should print the lines in the following format: Line cnum> has the following line up: refers to the current line number, which should start at 1 and increment by 1 for each ine, and refers to the soldiers" formation There should be two spaces in between the numbers representing the positions a. b. Continued Homework 8-Low Level File VO Example: >> formation([3 51 formation1.txt') Formation1.txt: 1l Line 1 has the following line up: 1 1 1 e 2l Line 2 has the following line up: 1 111 1 3l Line 3 has the following line up: e 1 e e Notes You are guaranteed that all numbers will be odd. There should not be an empty new line at the end of the file . Hints . Think about how you can find the center of each line and index from there. . The zeros) function may be helpful . What happens when you call num2str) on a vector of doubles

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems 12th Asian Conference ACIIDS 2020 Phuket Thailand March 23 26 2020 Proceedings

Authors: Pawel Sitek ,Marcin Pietranik ,Marek Krotkiewicz ,Chutimet Srinilta

1st Edition

9811533792, 978-9811533792

More Books

Students also viewed these Databases questions