Azzera filtri
Azzera filtri

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

9 visualizzazioni (ultimi 30 giorni)
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 Commenti
Walter Roberson
Walter Roberson il 29 Ago 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

Accedi per commentare.

Risposta accettata

Stephen23
Stephen23 il 30 Ago 2019
Modificato: Stephen23 il 30 Ago 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 !

Più risposte (1)

Mahesh Taparia
Mahesh Taparia il 30 Ago 2019
Modificato: Mahesh Taparia il 30 Ago 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 Commenti
Rik
Rik il 30 Ago 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 il 30 Ago 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.

Accedi per commentare.

Categorie

Scopri di più su Variables in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by