Assignment InstructionsThe purpose of this assignment is to show that you can...+ Read data from a file.« Write data to a file« Plot data.In Projectile Motion...Given an initial velocity,...

1 answer below »
language is matlab


Assignment Instructions The purpose of this assignment is to show that you can... + Read data from a file. « Write data to a file « Plot data. In Projectile Motion... Given an initial velocity, “v", the degree angle from the ground, “a”, and gravity “g"... The initial velocity in the x and y directions are... vx =v * cosa * (2% pi/360)) vy =v *sin(a * (2* pi/360)) The time of flight, “t", is... t=2%vy/g And the distance range it traveled “r" is... r=vx*t You decided to test these equations by running experiments with a "tennis ball", a "base ball", and a "lead ball" over several initial velocities and angles. You collected data and saved it in two files results1.txt | and results2.txt 1 . The row format of the files are... Objectiame Velocity Distancel Distance2 Distance Distance Distances Distances Distance? Distances ..where "Distance" is the value "ObjectName" traveled with an initial velocity of "Velocity" and at an angle of "10", "Distance2" for at an angle of "20", ..., and "Distance8" for at an angle of 80. ObjectName is a single word. Velocity is a positive integer. Distance1-8 are floating point numbers. Each value is separated by a single space and each row is terminated by the "\n' character. For this homework assignment you will... that order. This function will create and write to a text file named "filename" in the same format « Create a function "writeDataFile" which takes two arguments: a character array "filename", and a cell array "data identified above for results1.txt | and results2.txt { . There is no return value. Include data from the cell array "data" which will have the following structure. { {char array} {uint16} {double} {double} {double} {double} {double} {double} {double} {double}; {char array} {uint16} {double} {double} {double} {double} {double} {double} {double} {double}; "" {char array} {uint16} {double} {double} {double} {double} {double} {double} {double} {double} } o Each cell array row represents another row to write to the file. The cell array columns are "ObjectName, Velocity, Distance1, Distance2, = For example... istance8" in that order. "writeDataFile" will return nothing. >> example data = { 'Objectl’, uint16(100), 1.1, 1. ‘Object?’ wintl6(200), 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, >> writeDataFile ('example_data.txt’ example data) ; See "example data.txt" here. L = DO THIS ONLY USING methods and practices demonstrated in class. These include... = Sequences or Vectors. = The functions "fopen", "fprintf", "fclose", etc... ontinue" statements = Arithmetic, relational and logical operations. = DO NOT USE other built-in matlab functions. ritematrix','writetable",'cvswrite", "save", "fwrite", or other similar functions. = Such as..."writecell" = If unsure, ask the instructor. = HINT: See ">> help fprintf" for formatting your print output. = HINT: It is easier to write only some characters at a time to a file, instead of trying to write an entire line all at once. = HINT: "\n' is used to represent a carriage return. « Create a function "readDataFile" which takes an argument: a character array "filename". results2.txt J . From that data it will create a cell array "data" variable which will have the following structure... in that order. This function will read the text file called "filename" in the same format identified above for results1.txt J and { {char array} {uint16} {double} {double} {double} {double} {double} {double} {double} {double}; {char array} {uint16} {double} {double} {double} {double} {double} {double} {double} {double}; {char array} {uint16} {double} {double} {double} {double} {double} {double} {double} {double} } o Each cell array row represents another row read from the file. The cell array columns are "ObjectName, Velocity, Distance, Distance2,....Distance8" in that order. "readDataFile" will return this cell array, "data" = For example... >> example data = readDataFile (’example data.txt') example data = 2x10 cell array Columns 1 through 5 {'Objectl'} {[100]} ([1.1000]} {[1.2000]} {[1.3000]} {'object2'} {[200]} {2.10001} {[2.2000]} {[2.30001} Columns 6 through 10 {[1.4000]} {[1.5000]} ([1.6000]} {[1.7000]} {[1.8000]} {[2.4000]} {[2.5000]} {[2.60001} {[2.7000]} {[2.80001} >> >> cellplot (example data); %save to example cellplot.png a) © = DO THIS ONLY USING methods and practices demonstrated in class. These include... = Sequences or Vectors. = The functions "textrea , etc... continue” statements = Arithmetic, relational and logical operations. = DO NOT USE other built-in matlab functions. = Such as." ‘readmatrix’,'readtable’,'textscan",'strread","'save", "csvread", or other similar functions. = If unsure, ask the instructor. = HINT: See ">> help textread" to format the read into the correct variable data types. = HINT: All numbers are returned as "double" so you may need to convert (or cast) them into another data type. * "unit16(10)" will create a floating point double "10" into an unsigned integer "10" ° Create a function "plotData" which takes two arguments: a cell array "data", and a character array "name"...in that order. This function will plot (on a single plot) all data included in "data". "name" is to be added as a subtitle for each plot. "plotData" will return nothing. Format plots with axis labels, point markers, grid lines, titles, subtitles, and legends. Legends have the format "ObjectName-ObjectVelocity". See the examples below for everything needed. = >> example data = readDataFile ('example data.txt'); >> plotData (example data, 'Example'); See "example data.png" here. ! « Give all your functions and scripts a descriptive help comment to inform the user of the arguments needed and result returned. which would be returned when using the help command. After downloading and installing the provided files and creating the functions, do the following... 1. Start Matlab, you should see a bunch of windows all touching each other, with the biggest one labeled “Command Window”, as was demonstrated in lecture. Click in Matlab's Command Window. Hit the return key and you should see a prompt printed by the computer: >> After the prompt, type diary homework6.txt This will make everything that will be typed in the command window (by either you or Matlab) also be copied into the file homeworké.txt. This file will be on the computer where Matlab is really running, 2. In the command window, type clear This will remove any previously assigned variables from the current workspace 3. In the command window, type help writeDataFile You should see the help for your custom function. 4. In the command window, type help readDataFile You should see the help for your custom function. 5. In the command window, type help plotData You should see the help for your custom function. 6. In the command window, type resultsl_data = readDataFile('resultsl.txt'); A cell array variable should be created called results1_data. 7. In the command window, type celldisp (resultsl data(2,:)); This should display all the data from row 2 in results1_data. 8. In the command window, type writeDataFile ('my_resultsl.txt', resultsl data); A file should be created called 'my_results1.txt' which includes the cell array data "results1_data". It should be identical to results1.txt. 9. In the command window, type plotData(resultsl data, 'Resultsl - NETID'); Replace NETID with your "netid". A plot should be created of the data from results1.txt. It should look like the following (with your NETID included)...
Answered 2 days AfterDec 06, 2022

Answer To: Assignment InstructionsThe purpose of this assignment is to show that you can...+ Read data from...

Baljit answered on Dec 09 2022
38 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here