MATLAB error when storing values in a matrix

  • Context: MATLAB 
  • Thread starter Thread starter Firepanda
  • Start date Start date
  • Tags Tags
    Error Matlab Matrix
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 3K views
Firepanda
Messages
425
Reaction score
0
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
 
Physics news on Phys.org
Why don't you convert index to integer, e.g.

X(int32(100*i+1),2)=Y(1,2)