Info

This question is closed. Reopen it to edit or answer.

Updating a matrix using a for loop and if clause. Causing expression to the left of the equals sign is not a valid target for an assignment.

1 view (last 30 days)
Hi all,
I'm trying to update a matrix so that values increment when another value is present in another dataset. However it seems that data(1,i) is not a valid target for an assignment. I can't seem to find out why. Any help is much appreciated.
xinc = 0.03125;
yinc = 0.015625;
zinc = 0.03125;
xnew = 0.5;
ynew = 0.25;
znew = 0.5;
data = zeros(3,5000);
for i = 1:1:5000
if(Seed0Orange(251,i) == 100);
{
data(i,1) = xnew;
xnew = xinc + xnew;
data(i,2) = ynew;
ynew = ynew + xinc;
data(i,3) = znew;
znew = znew + zinc;
}
end
end

Answers (2)

Iain
Iain on 13 Aug 2014
The problem is that you have included
{ and } around the code. Remove those and it'll work.

Andrei Bobrov
Andrei Bobrov on 13 Aug 2014
add = [0.03125,0.015625,0.03125];
d1 = [0.5,0.25,0.5];
t = Seed0Orange == 100;
n = nnz(t);
data = zeros(3,5000);
data(t,:) = cumsum([d1;ones(n-1,1)*add]);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!