Assigning value to vector in based on conditional
Mostra commenti meno recenti
I'm trying to execute the following loop:
for m =1:length(r)
if imag(prelimsixmmrebar(m)) ~= 0
prelimsixmmrebar(m) = 4*2*Rc(m)*asin(r(m)/Rc(m))
end
end
with
r = 0.5:2.5;
h = (0.4/1.75)*r;
Rc = ((h.^2)+(r.^2))./(2.*h);
and
prelimsixmmrebar = ceil(180./acos((1.1^2)./(2*(r.^2)))).*2.*Rc.*asin(r./Rc)
If I understand correctly, the line inside the "if" statement should assign a new value only to the first element in prelimsixmmrebar, since this is the only one for which the boolean is true.
However, running the code reassigns new values to all of the elements. Using breakpoints to analyze, it seems that the reassignment is definitely happening at the line inside the "if" statement.
What am I missing? How would I reassign the value of the element - and only the value of that element in the vector prelimsixmmrebar?
Thanks in advance!!
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!