- #1
phillyj
- 30
- 0
Hi, I needed to write a function that takes a boolean vector and returns the position of the "1" values only. The correct way it was done was like this :
I don't understand why the "if" statement returns only the value "1"? I thought that I might have to make a boolean statement that checks if the value at "k" is equal to "1" like this "if x(k) ==1"
Please help, it's very confusing to me
Code:
function res = tmp(x)
res=[ ];
for k=1:length(x)
if x(k)
res = [res,k];
end
end
I don't understand why the "if" statement returns only the value "1"? I thought that I might have to make a boolean statement that checks if the value at "k" is equal to "1" like this "if x(k) ==1"
Please help, it's very confusing to me