Problem with answer 15.2 Creating and Calling Functions: (4/6) Create and Call a Function, task 1 MATLAB Fundamentals
43 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Gareth George
el 4 de Mayo de 2020
Comentada: Lester
el 9 de Oct. de 2023
The problem asks us to modify the function call using two inputs. I put the answer as follows:
top5 = getLargestN(x,5)
i get a message 'error using exercise>getLargestN too many input arguments'.
The answer i solution is identical to one I gave. How do I move forward here?
0 comentarios
Respuesta aceptada
Geoff Hayes
el 5 de Mayo de 2020
Gareth - did you update the function signature as well so that it accepts two inputs? Presumably you have defined the function (with body) like
function [res] = getLargestN(x)
and you would need to change this to
function [res] = getLargestN(x,y)
% do something in code with y
so that the signature matches how you are calling it (when you pass in the x and 5).
3 comentarios
Geoff Hayes
el 5 de Mayo de 2020
Gareth - I would first try to get the function returning the correct response (I don't understand either what "check that x is not modified" means). So right now your function is
function Y= getLargestN(x,5)
top5=Y
end
There are a couple of problems. The signature defines the output parameter and the input parameters. These parameters are variables and since 5 is not a variable (but a value) you cannot define it as a parameter. (You can pass 5 into this function when you call it.) So change this to something like
function Y = getLargestN(x, numElements)
Try to name the variables as to their purpose. Next, the output parameter is Y but is not set anywhere in your code. In fact, you are trying to use it before it has been defined. (I think the top5 variable is meant to be the output from this function when you call it...and not a variable within the function because you don't know how many elements you will be asked to extract.
function Y = getLargestN(x, numElements)
Y = ...;
end
Más respuestas (3)
Sanket
el 4 de Nov. de 2022
y0 = 0.4;
yline(y0)
tzerox = findcrossing(t,x-y0)
tzeroy = findcrossing(t,y-y0)
0 comentarios
Bhavesh Pawar
el 11 de Mzo. de 2022
y0 = 0.4;
yline(y0)
tzerox = findcrossing(t,x,y0)
tzeroy = findcrossing(t,y,y0)
5 comentarios
Joed Blair Jacalan
el 12 de Ag. de 2023
- Modify the definition of the findcrossing function so that it takes a third input z.
- Add a new line to the beginning of the function:y = y - z;
- In the Task 1 section of the script, change the value of y0 to 0.4.
- Modify the two calls to findcrossing to add y0 as an input.
You can use the graph to check that the returned values of t are correct (x(t) = 0.4 and y(t) = 0.4)
0 comentarios
Ver también
Categorías
Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!