How to use for loop and ifelse condition with Nx1 matrix.

1 view (last 30 days)
A:N x 1 matrix.
n = size(A,1)
for i = 1:n % increment 1
if A(i,1) = 5 % Error: The expression is to the left....
A(i,1) = 1 % when A(i,1) = 5 , replace A(i,1) original value to 1.
Error message.
Error: The expression to the left of the equals sign is not a valid target for an assignment.
Do you know how to replace original values in a matrix to a specific value on the basis of comparision between matrix value and a value such as 5?

Accepted Answer

Walter Roberson
Walter Roberson on 17 Nov 2015
MATLAB uses == for comparisons, not =

More Answers (0)

Categories

Find more on Multidimensional Arrays 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!