Matrix non-exceeding condition

조회 수: 1 (최근 30일)
Lev Mihailov
Lev Mihailov 2019년 8월 6일
댓글: Guillaume 2019년 8월 6일
Hello! I have a 1x15 matrix, the code is presented
[xdata,x]=min(Data); % Data 45x350 x=[ 16 16 16 31 16 0 16....]
a=[15 15 15 15 15....] % 1x350
for i = 1:length(x)-1
if x(i)+a(i)>a(i)
ax=Data((x(i)-a(i):x(i)),i) ;
ay=Data((x(i):x(i)+a(i),i) ;
A{i}=ax;
B{i}=ay;
else x(i)+a(i)<a(i) ;
ax=0 ;
ay=0 ;
A{i}=ax;
B{i}=ay;
end
end
%%% x(i)+a(i) 31+15=46
It so happened that in one value x (i) + a (i) exceeds the size of the matrix, can anyone tell me the condition how can I get around this?
  댓글 수: 4
Lev Mihailov
Lev Mihailov 2019년 8월 6일
편집: Lev Mihailov 2019년 8월 6일
if x(i)+a(i)>size(Data) % in my case it's 45
ax=0; % it was just written that it was zero
else x(i)+a(i)<a(i)
ax=0;
Something is needed
Guillaume
Guillaume 2019년 8월 6일
Something is needed
Yes, some much better explanation of what you're trying to do.
Once again,
else x(i)+a(i)<a(i)
ax=0;
is the same as
else
x(i)+a(i)<a(i) %useless statement that will print 0 in the command window
ax=0;
Perhaps, you meant something entirely different:
elseif x(i)+a(i)<a(i)
ax=0;
but until you explain in words what you're trying to do, we can't know for sure.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by