MATLAB received an unknown error message.

Asked 1 years ago, Updated 1 years ago, 83 views

MATLAB creates a simple program.When I tried to run the function (below), I got an error message.The function's content is to skip a variable to a function, return 200 to the return value if the calculation exceeds 100, or return the calculation as it is.

 function T=Tx(n) 
    i=(n+3)^7
   % return 200 if i is greater than 200
   if(i>200)
    T = 200;
   else
    T=i; 
  end

When I tried to run the above function, I received an error message similar to the following:

Cannot convert symfun to logical
  Error (line 4)
   if(i>200)

I don't know the cause, and I'm in a situation where I can't do anything.I would appreciate it if someone could do their best.

matlab

2022-09-30 14:47

1 Answers

Symbolic Math toolbox is installed.I don't know much about it either, but I think the following is probably happening.

Since the symbolic function A(t) is passed to the function Tx(n), the variable i in Tx is also

(A(t)+3)^7

It is a symbolic function such as .In addition, if(i>200) and i>200 are also

200<(A(t)+3)^7

The symbolic function is as shown in .

Now that the if statement is a statement, not an expression, it actually evaluates 200<(A(t)+3)^7 to try to do either if or else.However, 200<(A(t)+3)^7 remains symbolic function (symfun) and does not have a specific value, so it cannot be converted to logical value (logical), resulting in an error.

I'm not sure what you want to do, but if you want to do something like a composite function, shouldn't you call it a specific value each time like Tx(A(3)?


2022-09-30 14:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.