Error using function: Too many input arguments.

조회 수: 5 (최근 30일)
Mounira
Mounira 2024년 1월 11일
댓글: Mounira 2024년 1월 13일
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

채택된 답변

Hassaan
Hassaan 2024년 1월 11일
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.

추가 답변 (2개)

Taylor
Taylor 2024년 1월 11일
"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
Taylor
Taylor 2024년 1월 11일
Can you provide us any additional information about the network you're using? Attaching code would be helpful.
Mounira
Mounira 2024년 1월 13일
thanks a lot for your help but I already got the answer, you can check it

댓글을 달려면 로그인하십시오.


Hassaan
Hassaan 2024년 1월 11일
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
Mounira
Mounira 2024년 1월 11일
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);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by