Convert logical variable into integer number
Show older comments
Hi! I think my problem is very simple. I have some boolean expressions in my code, which the results will always be 1 or 0 (true or false). Here are some examples:
data=data+(-1*(~mat(i)&&mat(j)&&mat(k)))||(~mat(i)&&~mat(j));
or
data=data+(~mat(i));
I have to convert these logicals 1s and 0s to int values. I've tried using abs() but it is not working.
Btw, I'm on R2015b.
I appreciate the help.
Thanks!
Accepted Answer
More Answers (2)
Kehn Wu
on 21 Dec 2021
0 votes
You could try sum()
Marcelo Moraes
on 10 Jan 2022
0 votes
In HDC Coder you can use the block
HDL CODER => LOGIC AND BIT OPERATIONS => BIT CONCAT
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!