The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Nested for loop not working properly
Replies: 1   Last Post: Jul 25, 2013 2:15 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 1
Registered: 7/25/13
Nested for loop not working properly
Posted: Jul 25, 2013 1:15 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Here is my code:

span = 450:10:550;
yy2 = NaN(size(span));
yy4 = NaN(size(span));
yy6 = NaN(size(span));
yy8 = NaN(size(span));
yy10 = NaN(size(span));

for i = [span];
for j = 1:size(span,2);
yy2(j) = F2(i);
yy4(j) = F4(i);
yy6(j) = F6(i);
yy8(j) = F8(i);
yy10(j) = F10(i);

Essentially, I want to know the value of a each column vector (F2, F4, etc) at a series of particular points (determined by span) and write that value into a slot in an empty matrix. This way, I'll have a single row vector that looks like this:

yy2 = [F2(450), F2(460), etc...]
yy4 = [F4(450), F4(460), etc...]

and so on.

But what I get instead is a single row vector filled with the last value determined by span that looks like this:

yy2 = [F2(550), F2(550), etc...]

I have a feeling that this is a very simple fix but I can't figure it out. Any help would be much appreciated!

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2017. All Rights Reserved.