I have a 10 X 10 matrix, A, created in MatLab. All the values in the matrix are between 0 and 100. Say that I want to:
- Replace all elements of A < 10 with zeros
- Replace all elemtns of A > 90 with infinity
- Extract all values between 30 and 50 to a new vector.
Can I do this without writing a script? I can easliy do this through a script with some simple for-loops, but are there any shortcuts available? Any help will be greatly appreciated!
All of these things are really easy to do using logical indexing:
Each of the operations above can be done quite easily using a one or two commands. However each operation must be done independent of the other two. You can’t do all 3 in one line.
1.
2.
3.
new vector is a vector and wont be square like A was