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

조회 수: 4 (최근 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
PUPPALA RAJENDHAR 17PHD0038
PUPPALA RAJENDHAR 17PHD0038 2019년 8월 29일
Thank you sir for your valuable suggestion. i will try to make a MWE
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