Operator '*' is not supported for operands of type 'struct'.
Mostra commenti meno recenti
Dear Sir
Nice Greeting
I get this Error
Operator '*' is not supported for operands of type 'struct'.
with this objective function
of =2.6773*x(1)+3.1007*x(2)+3.2178*x(3)+ 3.8021*x(4)+3.6727*x(5)+3.0442*x(6)+1.6362*x(7)+3.0479*x(8)+3.3917*x(9)+3.7468*x(10)+3.8989*x(11)+3.1073*x(12)+3.3207*x(13)+ 1.6382*x(14);
How can I solve this Error
Thanks in advance
4 Commenti
Walter Roberson
il 4 Ott 2021
what is class(x) when you stop in the function? How is the function being invoked?
Andrea Strappato
il 4 Ott 2021
Hi,
The Matlab struct type is defined as "struct_name = struct('element_name', Array)" where Array is the set of x(i) values. So to extract the x(i) value try to write "struct_name(i).x".
tahseen alshmary
il 4 Ott 2021
Andrea Strappato
il 4 Ott 2021
x(i) is the i-values/element from your x struct data type. So , for example, to get the i-th element from x try this: "struct_name(i).x".
Can you show your struct x data type?
Risposta accettata
Più risposte (2)
tahseen alshmary
il 4 Ott 2021
1 voto
tahseen alshmary
il 4 Ott 2021
Modificato: Walter Roberson
il 4 Ott 2021
10 Commenti
Walter Roberson
il 4 Ott 2021
Please post your entire code.
tahseen alshmary
il 4 Ott 2021
Andrea Strappato
il 4 Ott 2021
What about the x variable? It's seems not defined.
tahseen alshmary
il 4 Ott 2021
Modificato: Walter Roberson
il 4 Ott 2021
Walter Roberson
il 4 Ott 2021
Okay, but please show one of the calls to ofun . We need to see what you are passing in to ofun()
tahseen alshmary
il 4 Ott 2021
Walter Roberson
il 4 Ott 2021
I do not see any call to ofun there. I see you constructing a function handle and assigning it to func, but I do not see you calling ofun or func .
The code you posted hints to me that you might have created your own genetic algorithm code ?
tahseen alshmary
il 4 Ott 2021
Modificato: Walter Roberson
il 4 Ott 2021
Walter Roberson
il 4 Ott 2021
Modificato: Walter Roberson
il 4 Ott 2021
Mathworks does not supply a function named PSO . The Mathworks particle swarm function is named particleswarm()
So we would need to know where you found the PSO.m function .
tahseen alshmary
il 4 Ott 2021
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
