Borrar filtros
Borrar filtros

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

9 visualizaciones (últimos 30 días)
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 comentarios
Walter Roberson
Walter Roberson el 29 de Ag. de 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

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 30 de Ag. de 2019
Editada: Stephen23 el 30 de Ag. de 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 !

Más respuestas (1)

Mahesh Taparia
Mahesh Taparia el 30 de Ag. de 2019
Editada: Mahesh Taparia el 30 de Ag. de 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 comentarios
Rik
Rik el 30 de Ag. de 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 el 30 de Ag. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Variables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by