MATLAB: Nested for loop outputs

for loop

Hopefully a simple question:
I've got a program with a for loop inside another for loop that looks something like this:
x=0:some value
for i = 100 iterations
T = defined equation
Tvalue(i) = T %this stores all 100 results of T in a matrix
if [condition logic]
% if true, repeat for next i
else
for j = 1000 iterations
T = %redefined equation
Tvalue(j) = T % different size matrix
end
end
plot(x,Tvalue)
Right now, my program is essentially working, but I want to take the last value of T(j) and input it as that iteration of i's value in the T(i) matrix and keep going until i = 100th iteration. In other words, (assuming condition logic is false) for i = 2, i want the 1000th iteration of T(j) to become the 2nd value of T(i) in the first matrix.
Right now the program appears to be having trouble with the matrices being different sizes.
Thank you for any guidance

Best Answer

I'm not sure if entirely understand the question... why not just do this for the last block?
for j = 1000 iterations
T = %redefined equation
some_other_matrix(j) = T
end
Tvalue(i) = some_other_matrix(1000)
If that doesn't answer the question, then I'd suggest you post more information. For example " the program appears to be having trouble" is pretty vague. If you are getting an error message, we'd need to see your entire code, and the exact error message.
Related Question