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

9 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2019-8-29
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

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2019-8-30
编辑:Stephen23 2019-8-30
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 !

更多回答(1 个)

Mahesh Taparia
Mahesh Taparia 2019-8-30
编辑:Mahesh Taparia 2019-8-30
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 个评论
Rik
Rik 2019-8-30
@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 2019-8-30
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Variables 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by