Why is it saying "the expression to the left of the equals is not a valid target for an assignment" / "parse error at =" on my if statements?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
tash7827
am 3 Aug. 2015
Beantwortet: Sebastian Castro
am 3 Aug. 2015
could you tell me why it is saying that every time I say 'time='x''? here is my code:
exp=zeros(60,96,10);
time=randi([3 7]);
if time=3
for j=1:size(exp,1);
for jj=1:size(exp,2);
rand=randi([1 8]);
exp(j,jj,rand:rand+2)=1;
end
end
elseif time = 4
for j=1:size(exp,1);
for jj=1:size(exp,2);
rand=randi([1 7]);
exp(j,jj,rand:rand+3)=1;
end
end
elseif time = 5
for j=1:size(exp,1);
for jj=1:size(exp,2);
rand=randi([1 6]);
exp(j,jj,rand:rand+4)=1;
end
end
elseif time = 6
for j=1:size(exp,1);
for jj=1:size(exp,2);
rand=randi([1 5]);
exp(j,jj,rand:rand+5)=1;
end
end
elseif time = 7
for j=1:size(exp,1);
for jj=1:size(exp,2);
rand=randi([1 4]);
exp(j,jj,rand:rand+6)=1;
end
end
0 Kommentare
Akzeptierte Antwort
Sebastian Castro
am 3 Aug. 2015
For logical expressions, you want to use the double equals operator:
if time == 3
% Do stuff
end
- Sebastian
0 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!