Effacer les filtres
Effacer les filtres

Substitution

2 vues (au cours des 30 derniers jours)
Ferd
Ferd le 28 Mar 2012
Hey
I need to substitute the last element of the Steps array with the LastStep value. This is my code for the section;
CycleStep = 0;
for k = 1:7
Steps(k) = 1;
CycleStep = CycleStep + 1;
if CycleStep == 7
LastStep = 10 - Steps(k)*(7 - 1);
end
end
Steps(Steps(7))=LastStep;
but somehow it is substituting the first value of the Steps array. How do I replace the last value of the Steps with the LastStep value?

Réponse acceptée

Wayne King
Wayne King le 28 Mar 2012
Just
Steps(end) = LastStep;
You are doing:
Steps(Steps(7))
but Steps(7) is 1, so your code is saying "Assign Steps(1) the value LastStep.
  1 commentaire
Ferd
Ferd le 28 Mar 2012
Oh yea... Thanks Wayne!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by