I am trying to vectorize an if statement in Matlab and I am not sure how to do it. I want to assign a 'N' for positive values and 'S' for negative values. I want to avoid a for loop but here is my code:
LatDD = [23.0,12.3,-43.2,9.9,-40.7]; LatDir = ['' '' '' '' '']; if (LatDD < 0) LatDir = 'S' else LatDir = 'N' end Obviously this fails to do what I want because it really only checks the first element of LatDD. I could easily do a for loop but I want it to be vectorized. I tried logical indexing but all that got me was another vector with zeroes or ones which I would have to check with a for loop anyway.