Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB error when storing values in a matrix

  1. Apr 2, 2012 #1
    Basically I have a function file set up called BSform.m, I'm confident this has nothing to do with my problem

    My problem is this driver file for the function

    X=zeros(101,2);
    for i = 0:0.01:1
    [C1,P1]=BSform(200,200,2,0,0.02,i);
    Y=[C1,P1]
    X(100*i+1,1)=Y(1,1)
    X(100*i+1,2)=Y(1,2)
    end

    My output Y ALWAYS gives me a 1x2 vector (this is what I want, the function is working as intended)

    I am trying to STORE this vector in my X matrix

    Everything is FINE up until i get to i=0.14, and I've no idea why

    The error I get is:

    ??? Attempted to access X(15,1); index must be a positive integer or logical.

    Error in ==> File2 at 5
    X(100*i+1,1)=Y(1,1)


    It's really weird since if I manually input this Y value it manages to access it fine and store it in X. I thought about overriding it and moving on, but then it screwed up when it hit X(29,1) and again at X(30,1) then again a few steps more, really irregular pattern.

    Any idea what's causing this? I've tried transposing it all, and the same problem hits at the same values for i.

    Thanks
     
  2. jcsd
  3. Apr 3, 2012 #2
    Why don't you convert index to integer, e.g.

    X(int32(100*i+1),2)=Y(1,2)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: MATLAB error when storing values in a matrix
Loading...