I have a simple equation that I want to get answers from for two diff inputs and am trying to use a for loop, but I keep getting the error "Subscript indices must either be real positive integers or logicals." or that matrix exceeds dimensions.

I have a simple equation that I want to get answers from for two diff inputs and am trying to use a for loop, but I keep getting the error "Subscript indices must either be real positive integers or logicals." or that matrix exceeds dimensions. The error is given in my line defining for i=
here is my script: (the other variables are all constants defined earlier)
qin=[41 68.24]; syms Tin
for i=1:length(qin);
Tin(i) = Tinf + ((qin(i).* Afloorin)/(hair * Awallout));
end

Answers (1)

length of qin should be 2, so that should not be a problem. You don't use a semicolon on the for line, so get rid of that. Try to use the debugger. Also, don't use i (the imaginary variable) as a loop counter. Try to put in debug statements like
maxIndex = length(qin) % No semicolon on this line so we can see it.
scalingFactor = Afloorin)/(hair * Awallout) % No semicolon.
for k = 1 : maxIndex
fprintf('k = %d, qin(%d) = %f\n', k, k, qin(k));
Tin(k) = Tinf + qin(k).* scalingFactor
fprintf('Tin(%d) = %f\n', k, Tin(k));
end

This question is closed.

Asked:

on 4 May 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!