If clause for EMG

1 次查看(过去 30 天)
Jan Faber
Jan Faber 2023-4-27
Good evening everyone,
sadly I have some problems with my current task for the university, it's one of the last tasks where we should automize the detection of different sections of a handdynamometer and neither my detection through if clause nor the code submitting values to the variables in the if clause is working.
When I use my if clause, I get the error: "Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values."
I attached the code and the measurements and will also show the example below here, if someone who is more experienced with matlab could probably help me, then I would be really thankful.
kind regarts JF
if (Laufzeitverzoegert_Hd>=0 && Laufzeitverzoegert_Hd<= 0.8487*10e07)
erster_Abschnitt_HD_dominant= Laufzeitverzoegert_Hd;
erster_Abschnitt_EMG_dominant_real= FIR_real_tau;
erster_Abschnitt_EMG_dominant_img= FIR_img_tau;
end

采纳的回答

Sugandhi
Sugandhi 2023-4-28
Hi Jan Faber,`
I understand that you are getting error "Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values." becuase of if statement in the code.
I have recreated the issue at my end.One of findings are that Laufzeitverzoegert_Hd is a matrix and you are using && for performing AND operation between matrices. && operator is used for logical scalar values.To perform logical AND operation you may use '&' operation.On using this operation the returned value will be also a matrix.
if statement that include arrays, are true only when every element in the array is nonzero.In your case resultant matrix don't have all 1's , hence the if statement didn't passed and didn't execute code under it.If you want to execute the assignment statements under if statements even if one or more entries in resultant matrix are 1, the you can use any function.
For more information, kindly go through following links:
  2 个评论
Jan Faber
Jan Faber 2023-4-28
Thanks a lot, I'll definitely give it a try.
Best regards
Jan C.F.
Walter Roberson
Walter Roberson 2023-4-28
A lot of the time when these situations arise, you should be using logical indexing.

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by