Error Accessing Index - Told index must be positive or logical, however it is both...

조회 수: 3 (최근 30일)
I am using a forloop to pull out values of one vector based on indecies specified by a second vector. My trial array is 500x6 and my events vector is 4x1 of two decimal numbers (i.e - 1.23, 3.42, 4.89). For certain columns in my trial array, I want to reset the start point to 0 and adjust all values in that cycle accordingly Here is what my code looks like
for cycle = 1:(length(events)-1)
initial_value = trial(events(cycle)*100, 11)
plot(linspace(0,1,100)*100, (interp1(linspace(0,1,length(trial(events(cycle)*100:events(cycle+1)*100, 11))), (trial(events(cycle)*100:events(cycle+1)*100, 11)-initial_value), linspace(0,1,100))))
end
When I do this, I get this error message:
Attempted to access trial(253,11); index must be a positive integer or logical.
However, my trial file does indeed contain the index 253, 11. Any ideas why I am getting this error?

채택된 답변

Andreas Goser
Andreas Goser 2012년 7월 17일
Maybe it is not exactly and integer, like 1.0000001.

추가 답변 (2개)

Sean de Wolski
Sean de Wolski 2012년 7월 17일
dbstop if error
Then wait until it errors and inspect your variables.
format long
will likely show you that Andreas' is correct.

Shawn
Shawn 2012년 7월 17일
I put in a round function on my events variable and it seems to have fixed it. I guess after looking for all the complicated answers I looked right past the simple one! Thank you

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by