Clear Filters
Clear Filters

Error using function: Too many input arguments.

17 views (last 30 days)
Hello,
so i have a prediction model code, with 15 inputs, and one output, and the code is working perfectly,
and i have saved the net file of this prediction, then I am trying to call a function with this net.file
the function:
script:
function outputPower = predictPVOutput(inputData)
load('net')
outputPower = net(inputData);
end
command window:
predictPVOutput(4,40,277,7,0,0,0.16,-30,3.2,0,0,96.2,1020,271,4)
error:
Error using predictPVOutput
Too many input arguments.
So what how can i call this function?
I have 15 inputs not 1,
Thanks in advance

Accepted Answer

Hassaan
Hassaan on 11 Jan 2024
Neural networks in MATLAB require that the input data is formatted correctly, often as a column vector with a number of rows equal to the number of input features the network expects.
Here's what you need to check and potentially correct:
  1. Input Size: Ensure that the number of elements in inputData matches the number of input neurons in the network. If the network was trained with 15 features, then inputData must be an array of 15 elements.
  2. Input Shape: Neural networks in MATLAB typically expect inputs to be column vectors where each column is a sample and each row is a feature. If you are providing a single sample (as in your case), your input should be a column vector of size [net.inputs{1}.size x 1].
Here's how you can modify your code to ensure the input is a column vector:
function outputPower = predictPVOutput(inputData)
load('net'); % Load your neural network model
% Ensure inputData is a column vector
inputData = inputData(:); % This will convert inputData to a column vector
outputPower = net(inputData);
end
Then, when you call predictPVOutput, make sure inputData is arranged as a column vector:
inputData = [4; 40; 277; 7; 0; 0; 0.16; -30; 3.2; 0; 0; 96.2; 1020; 271; 4];
output = predictPVOutput(inputData);
If your network expects data normalized in a certain way (for example, between -1 and 1, or 0 and 1), you must also preprocess your input data in the same way it was preprocessed during training before passing it to the network.
Lastly, if the network was trained with batch data or time-series data, the input data might need to be formatted accordingly. Check the training code to confirm how the input data was shaped. If you can't resolve the issue with these suggestions, you might need to look back at how the network was trained and how the training data was formatted.
---------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

More Answers (2)

Taylor
Taylor on 11 Jan 2024
"net" is not configured for as many inputs as you are providing. You will either need to reduce your number of inputs or edit the network to accept 15 inputs.
  3 Comments
Taylor
Taylor on 11 Jan 2024
Can you provide us any additional information about the network you're using? Attaching code would be helpful.
Mounira
Mounira on 13 Jan 2024
thanks a lot for your help but I already got the answer, you can check it

Sign in to comment.


Hassaan
Hassaan on 11 Jan 2024
function outputPower = predictPVOutput(inputData)
load('net'); % Load your neural network model
outputPower = net(inputData);
end
Now, you should create an array or matrix that contains your 15 input values and pass that array as a single input argument to the function. For example:
inputData = [4, 40, 277, 7, 0, 0, 0.16, -30, 3.2, 0, 0, 96.2, 1020, 271, 4];
output = predictPVOutput(inputData);
---------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.
  1 Comment
Mounira
Mounira on 11 Jan 2024
thank you for your answer, but I have already tried it like this, and i got this:
Error using network/sim
Input data sizes do not match net.inputs{1}.size.
Error in indexing (line 15)
otherwise, v = sim(vin,subs{:});
Error in predictPVOutput (line 3)
outputPower = net(inputData);

Sign in to comment.

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!