Hi @Eve,
The error message "not enough input arguments" typically indicates that the function CreatePoints is being called without the required parameters, lowValue and highValue. In MATLAB, when you define a function that requires input arguments, you must provide those arguments when calling the function. Let me break down the solution step-by-step, making sure that you have a complete understanding of how to implement this correctly.
Step 1: Define the Function
You have already defined the function correctly. Here’s the code you provided, which is mostly correct:
% Define the function function plotPoints = CreatePoints(lowValue, highValue) % lowValue: Starting value in plotPoints % highValue: Ending value in plotPoints % Construct a row array plotPoints with 5 linear-spaced % points from lowValue to highValue plotPoints = linspace(lowValue, highValue, 5); end
Step 2: Calling the Function
To call this function correctly, you need to provide the lowValue and highValue arguments. You can do this in the MATLAB command window or in a separate script (M-file). Here’s how you can call the function:
% Call the function with example values pts = CreatePoints(1, 10);
Step 3: Complete Example
To ensure that everything works seamlessly, here’s a complete example that includes both the function definition and the function call. You can place this code in a single M-file or run it in the command window:
% Define the function function plotPoints = CreatePoints(lowValue, highValue) % lowValue: Starting value in plotPoints % highValue: Ending value in plotPoints % Construct a row array plotPoints with 5 linear-spaced % points from lowValue to highValue plotPoints = linspace(lowValue, highValue, 5); end
% Call the function with example values pts = CreatePoints(1, 10);
% Display the result disp(pts);
Please see attached.
For more information on linspace function, please refer to
https://www.mathworks.com/help/matlab/ref/double.linspace.html
Make sure that you are not trying to run the function directly by clicking the green "Run" button in the MATLAB editor without providing the necessary input arguments. Instead, you should run the function from the command window or include the function call in a script. If you continue to encounter issues, double-check that the function is saved in a file named GeneratePoints.m and that you are calling it from the same directory or have the directory added to your MATLAB path.By following these steps, you should be able to resolve the error and successfully create a linear-spaced points array in MATLAB.
Also, @Walter Roberson provided some good points regarding to your comments especially, “Note that the overall code could not be named CreatePoints.m (that is, a script may not be named the same as a function inside the script.)”
Hope this helps.
If you have any further questions or need additional assistance, feel free to ask!