Problem with running a Matlab code.

조회 수: 10 (최근 30일)
WAN NOR NAZIRA MUSTAPA KAMAL
WAN NOR NAZIRA MUSTAPA KAMAL 2021년 1월 21일
I am having problem with the code where when I first run the code, the outcome that I get is data in values and graph but when I want to re run the code for the second time and so on, the outcome that I get is zero data values and the graph is in straight line. I am using MATLAB R2019a.Can you please help me to solve this problem.

채택된 답변

Daniel Pollard
Daniel Pollard 2021년 1월 21일
Clear your variables by putting the command
clear
at the start of your programme. It's almost certainly holding onto variables which affects repeated runs.
  댓글 수: 1
WAN NOR NAZIRA MUSTAPA KAMAL
WAN NOR NAZIRA MUSTAPA KAMAL 2021년 1월 21일
I have already do it but it still give the same results when I re run the codes. This is the codes:
%% setup
hold all
a = arduino('COM3', 'Uno');
mpu = i2cdev(a,'0x68'); %mpu adress is normally 0x68
writeRegister(mpu, hex2dec('B6'), hex2dec('00'), 'int16'); %reset
data = zeros(10000,14,'int8'); %prelocating for the speed
j = 1;
a1 = animatedline('Color',[1 0 0]);
a2 = animatedline('Color',[0 1 0]);
a3 = animatedline('Color',[0 0 1]);
legend('Accel_x','Accel_y','Accel_z')
%% loop
while(true)
x=1;
for i=59:72 % 14 Data Registers for Accel,Temp,Gyro
data(j,x) = readRegister(mpu, i, 'int8');
x = x + 1;
end
y = swapbytes(typecast(data(j,:), 'int16')) %if your system is big-endian remove the swapbytes function
addpoints(a1,j,double(y(1)));
addpoints(a2,j,double(y(2)));
addpoints(a3,j,double(y(3)));
j = j+1;
drawnow limitrate
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by