how to rectify the error Index exceeds matrix dimensions.?

조회 수: 1 (최근 30일)
prajwal prabhu
prajwal prabhu 2017년 4월 27일
편집: Torsten 2017년 4월 27일
i am doing real time plotting of my sensor output in matlab. How to rectify the above error.This is my code.
if true
clc
clear all
close all
a=arduino('com13','uno');
a1_pin='D9';
tic;
i=0;
while (toc<inf)
i=i+1;
t(i)=toc;
v(i)=readDigitalPin(a,'D2');
plot(t,v,'b')
axis([0 inf 0 3])
pause(0.1)
if((v(i)-v(i+1)==1)) tic else d(i)=toc; end end
end

답변 (1개)

Torsten
Torsten 2017년 4월 27일
When you enter the if-statement, v(i+1) does not yet exist because the array v is only constructed up to element v(i).
Best wishes
Torsten.
  댓글 수: 2
prajwal prabhu
prajwal prabhu 2017년 4월 27일
how to rectify the above code???
Torsten
Torsten 2017년 4월 27일
편집: Torsten 2017년 4월 27일
Rectify the error that v(i+1) is undefined within the if-statement.
That's the only thing I can tell since I don't know what you are trying to do in your code.
Best wishes
Torsten.

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

카테고리

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