How can we store the each single calculation in the "For" loop into the separate array?

1 view (last 30 days)
Hello everyone,
I need to store the length calculation in separate array. However, I do not know why matlab only records the last value, and every thing else is zero.. I would like to store the value of each calculation in the separate vector.
Below is my code.
%Start FOR loop
for k = 1:3:N
%Set up the start codon
if StartPt == 0
if dna(k) == A && dna(k+1) == T && dna(k+2) == G
StartPt = k;
end
else
if dna(k) == T && dna(k+1) == A && dna(k+2) == A
StopPt= k;
elseif dna(k) == T && dna(k+1) == A && dna(k+2) == G
StopPt = k;
elseif dna(k) == T && dna(k+1) == G && dna(k+2) == A
StopPt = k;
%Length calculation
Length = StopPt - StartPt + 3;%Need to store the length
Thank you,

Answers (1)

Walter Roberson
Walter Roberson on 22 Jul 2018
Instead of assigning to Length, assign to Length((k-1)/3+1)
Storing the every result in a separate vector is recommended against. Use a multidimensional array or cell array instead.

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!