MATLAB Answers


Displaying all values from a for loop in one vector

Asked by Rebecca
on 22 Jan 2013

Hi everyone. I know people have asked similar questions to this one, but I am a complete novice with MATLAB and have been unable to generalise the answers to my own problem.

I'd like all the answers generated in this loop to be displayed as one vector so that I can export them to Excel for an analysis. This is the loop:

for t=600:600:28800

It's a very simple loop, but I am stuck! sumA is a vector of values from another loop.

Thanks for any assistance!




No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 22 Jan 2013
 Accepted answer

sum(bsxfun(@lt, sumA(:), 600:600:28800))

Or, more generally,

tvals = 600:600:28800;
numT = length(tvals);
L = zeros(numT, 1);
for K = 1 : numT
  t = tvals(K);
  L(K) = length(find(sumA<t));

Then you could write L

  1 Comment

Wow, what a quick response. It worked a charm and I see what you did. Thanks so much!

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!