- & operation: https://www.mathworks.com/help/matlab/ref/and.html
- if statement: https://www.mathworks.com/help/matlab/ref/if.html?searchHighlight=if&s_tid=srchtitle_if_1
- &&operation: https://www.mathworks.com/help/matlab/ref/shortcircuitand.html?searchHighlight=%26%26&s_tid=srchtitle_%2526%2526_1#mw_543464a1-bc87-4c8f-8f59-063f73903fd2
- any fuction: https://www.mathworks.com/help/matlab/ref/any.html?searchHighlight=any&s_tid=srchtitle_any_1
If clause for EMG
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jan Faber
am 27 Apr. 2023
Kommentiert: Walter Roberson
am 28 Apr. 2023
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
0 Kommentare
Akzeptierte Antwort
Sugandhi
am 28 Apr. 2023
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 Kommentare
Walter Roberson
am 28 Apr. 2023
A lot of the time when these situations arise, you should be using logical indexing.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!