too many input arguments error when i pass struct to my function
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
muhammad ilyas khattak khattak
am 14 Mai 2021
Kommentiert: muhammad ilyas khattak khattak
am 14 Mai 2021
I am getting too many input arguments error when i pass struct to my function... struggling since last 2 days.... help requested....my called function and calling matlab script both files are attached :::
2 Kommentare
per isakson
am 14 Mai 2021
Bearbeitet: per isakson
am 14 Mai 2021
"many input arguments error when i pass struct to my function" I fail to reproduce any such error on R2018b.
First I ran SwarmOptimization14May2021 and encountered
Undefined function or variable 'Vehiclen'.
Error in SwarmOptimization14May2021 (line 79)
U(Vehiclen)
Then I commented out the two final lines
U(Vehiclen)
t(Vehiclen)
and ran SwarmOptimization14May2021 again. This time without errors.
All calls of CostTimeDCal1 are commented out in SwarmOptimization14May2021
muhammad ilyas khattak khattak
am 14 Mai 2021
Bearbeitet: muhammad ilyas khattak khattak
am 14 Mai 2021
Akzeptierte Antwort
Walter Roberson
am 14 Mai 2021
f = @(x)CostTimeDCal1;
That says that when f is called, it should ignore its single input parameter and call CostTImeDCal1 with no input parameters. Are you sure that is what you want?
[Ur,tr] = f(x.n(n),x.U(n),x.t(n),x.Lambda(n),x.Betam(n),x.VarAlpha(n),x.fl(n),x.fe(n));
and there you call f with 8 input parameters. But f only expects one input parameter (which it would ignore anyhow.)
The code that is most likely for this kind of situation is:
f = @CostTImeDCal1;
and
[Ur,tr] = f([x.n(n),x.U(n),x.t(n),x.Lambda(n),x.Betam(n),x.VarAlpha(n),x.fl(n),x.fe(n)]);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Argument Definitions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!