Array indices must be positive integers or logical values.

조회 수: 5 (최근 30일)
Irfan Tariq
Irfan Tariq 2019년 9월 9일
댓글: Stephen23 2019년 9월 9일
I am getting above error.
data_out(i,1:dtn)=data_in_temp(colum-dtn+1):colum)
where dataout =1586*128 double
row=1586;
colum=128
dtn=129;
data_in_temp=1*128
  댓글 수: 4
Bjorn Gustavsson
Bjorn Gustavsson 2019년 9월 9일
colum-dtn+1
should become 0 with the values you've given, matlab uses 1-based indexing, so your indices has to be larger than zero. Possibly your left-hand-side index i is also unallowed, but if you've set that one to a positive integer then it's OK (I've stopped use i and j as indices - sooner or later one tend to use them for their purpose of the imaginary 1i. Instead I use i1, i2 and j1 etc for simple loop-variables, that saves me from occasional but very irritating bugs and errors.)
HTH
Fabio Freschi
Fabio Freschi 2019년 9월 9일
true, but the error pointed out by the OP is about wrong indexing

댓글을 달려면 로그인하십시오.

답변 (2개)

Stephen23
Stephen23 2019년 9월 9일
편집: Stephen23 2019년 9월 9일
Check your indexing:
>> colum = 128;
>> dtn = 129;
>> colum-dtn+1
ans = 0
MATLAB indexing start at 1.
  댓글 수: 2
Irfan Tariq
Irfan Tariq 2019년 9월 9일
so what should be the valid syntax for the above soultion.
Stephen23
Stephen23 2019년 9월 9일
data_out(i,:) = data_in_temp;

댓글을 달려면 로그인하십시오.


TADA
TADA 2019년 9월 9일
in Matlab, matrix indices start from one, not zero like other programming languages, but your index starts from zero:
colum-dtn+1 = 0
so what you are actually doing is this:
data_out(i,1:129)=data_in_temp(0:128)
I guess what you did try to do is more like copy the entire row of data_in_temp into the i'th row of data_out?
if so, try this:
data_out(i,:) = data_in_temp
or if you are trying to copy a subset of that row, make sure the index of data_in_temp is the same size as that of data_out

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by