>Is this correct? ---> Yes, it is correct syntax. No, it does not behave as you expect.
cA = randi(10,[3 10]); i = 1; NC = 5;
cA(i+1,cA(i+1,:)<NC) = NC
Now you are trying the third indexing approach. Please check out it.
>In MATLAB®, there are three primary approaches to accessing array elements based on their location (index) in the array. These approaches are indexing by position, linear indexing, and logical indexing.
- Indexing with Element Positions
- Indexing with a Single Index
- Indexing with Logical Values
> Expressions that include relational operators on arrays, such as A > 0, are true only when every element in the result is nonzero.
if statement is not needed in this question's case, but if you use if statement, you have to know that above specfication of if statement.