Using user defined Function with a Table of variables , through a For Loop

I need to use my function=func(R,H,V,Vm) in a for loop and calls each of the 5 rows of R,H,V values from a provided 3x5 table and W is hard coded as Vm=1000.
I'm rusty on my 'for loops' and could not get it to work correctly.
Here is the assignment: 1. Write a function that calculates the launch angle, given the target range, altitude and velocity and cannon’s muzzle velocity. Function specifications: Input arguments: Range (R) in meters; Altitude (H) in meters; Target velocity (V) in m/s; Muzzle velocity (Vm) in m/s [the arguments must be in this order and the tolerance must be 0.001 or better.] Output argument: The required launch angle in degrees. Use the following test case to validate your function: R = 7,000 m; H = 2,500 m; V = 225 m/s; Vm = 1,000 m/s theta = 25.65 2. Write a script to apply your function from task 1 to a set of provided target data. a. Load the target data from the provided Excel file, targets.xlsx, into a matrix using the command data = xlsread(‘targets.xlsx’); • Each row of the data file contains the parameters for one target, in the following order: Range, Altitude, Velocity • Use a fixed value of 1,000 m/s for Vm.
b. Loop over the targets, calling the iterative solver function to determine the launch angle for each one. • Extract the parameters from the data array that you created in 2a; do not hard-code the numbers or the number of targets. (In other words, your program should work just as well if applied to a different data file.) • Store the solutions (the calculated launch angles) in a row vector called angles.

2 件のコメント

Image Analyst
Image Analyst 2018 年 10 月 8 日
Clear as mud. Please provide the inputs X, Y, and Z, and provide the desired output. Also provide the unnamed "provided 3x5 table" - provided to you maybe but you didn't provide it to us. For now about all I can say is
W=1000
for k = 1 : whatever
output = func(W, X, Y, Z)
end
Alan Austin
Alan Austin 2018 年 10 月 8 日
編集済み: Alan Austin 2018 年 10 月 8 日
Here are the values. sorry i was not clear in my question, i didnt need this problem solved anymore but i am just trying to get a better understanding for next time. Any help is appreciated

サインインしてコメントする。

回答 (1 件)

Peter Perkins
Peter Perkins 2018 年 10 月 12 日

0 投票

If "table" means the table data type, then rowfun is designed for exactly this. Of course, it doesn't really stay within the lines of the assignment ...

カテゴリ

タグ

質問済み:

2018 年 10 月 8 日

回答済み:

2018 年 10 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by