Error: The expression to the left of the equals sign is not a valid target for an assignment.

4 vues (au cours des 30 derniers jours)
Ycomfort=str2func(strcat('@(x,T_set_r,T_room_m,T_room_mm,DT_m,DT_L,DT_U,T_room,Gt,dc,Q_HVAC,N_slot,T_set_w,dT_L,dT_U,Tw_m,Tw_mm,f_t,G,Bt,Rt,dT_m,T_w,T_env,T_n,Q_CHPU)',Fcomfort));
Error: The expression to the left of the equals sign is not a valid target for an assignment.
  5 commentaires
PUPPALA RAJENDHAR 17PHD0038
PUPPALA RAJENDHAR 17PHD0038 le 29 Août 2019
Thank you sir for your valuable suggestion. i will try to make a MWE
Walter Roberson
Walter Roberson le 29 Août 2019
The most common cause for this problem is that you are in the middle of a [ or { matrix definition, that you forgot a ] or } or accidentally commented it out

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 30 Août 2019
Modifié(e) : Stephen23 le 30 Août 2019
As Walter Roberson already wrote, the problem is most likely caused by unmatched curly braces or square brackets earlier in the code. This error is easy to demonstrate, e.g. in a script which mimics your code flow:
baz = @(a,b)a+b;
str = 'baz(a,b);';
vec = {1,2,; % !!! unmatched curly brace !!!
foo = str2func(strcat('@(a,b)',str));
foo(2,3)
which when run throws exactly the error that you are getting:
>> temp5
Error: File: temp5.m Line: 6 Column: 5
The expression to the left of the equals sign is not a valid target for an assignment.
Here is a much simpler demonstration of this error, showing that the error is unrelated to str2func or strcat or functions in particular:
vec = {1,2,; % !!! unmatched curly brace !!!
foo = 23
giving:
>> temp5
Error: File: temp5.m Line: 5 Column: 5
The expression to the left of the equals sign is not a valid target for an assignment.
Solution: check your brackets/braces !

Plus de réponses (1)

Mahesh Taparia
Mahesh Taparia le 30 Août 2019
Modifié(e) : Mahesh Taparia le 30 Août 2019
Hi,
You can use the below command:
Ycomfort=str2func('@(x,T_set_r,T_room_m,T_room_mm,DT_m,DT_L,DT_U,T_room,Gt,dc,Q_HVAC,N_slot,T_set_w,dT_L,dT_U,Tw_m,Tw_mm,f_t,G,Bt,Rt,dT_m,T_w,T_env,T_n,Q_CHPU)Fcomfort(varargin)');
Where Fcomfort is the function of the mentioned variables.
You can refer the below link for more help for str2func:
  10 commentaires
Rik
Rik le 30 Août 2019
@Mahesh can you try to make an example with your syntax that can actually run without errors? Whenever I get questioning comments from other users, I always make sure that the code I'm suggesting runs at least on my system.
Walter Roberson
Walter Roberson le 30 Août 2019
You can code
Ycomfort=str2func('@(x,T_set_r,T_room_m,T_room_mm,DT_m,DT_L,DT_U,T_room,Gt,dc,Q_HVAC,N_slot,T_set_w,dT_L,dT_U,Tw_m,Tw_mm,f_t,G,Bt,Rt,dT_m,T_w,T_env,T_n,Q_CHPU)Fcomfort(x,T_set_r,T_room_m,T_room_mm,DT_m,DT_L,DT_U,T_room,Gt,dc,Q_HVAC,N_slot,T_set_w,dT_L,dT_U,Tw_m,Tw_mm,f_t,G,Bt,Rt,dT_m,T_w,T_env,T_n,Q_CHPU)');
but remember that the effect of that would be to index the character vector fcomfort, not execute a function named fcomfort.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Variables dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by