Why does it say that it exceeded the array if the array is larger than the data it receives? arduino-matlab

3 ビュー (過去 30 日間)
Index exceeds matrix dimensions.
I am sending some data from arduino to matlab but, the error message ->>>Index exceeds matrix dimensions. Error in grafica (line 29 v2(muestras)=(valor(2));<<<-
that appears, it appears to me but after I graph the points, I mean ending the while cycle. I suspect maybe, that you are asking for data that does not exist in the matrix or something like that but I can't solve it. Technically it does not affect me because I manage to graph my points and that error mentions it to me until the end but, I would like you not to tell me that error anymore, how could I solve it? thank you very much
<<<<CODE>>>>>>>>>>>><
function arduinomatlab
n=21
v1=zeros(1,1000);
v2=zeros(1,1000);
delete(instrfind({'Port'},{'COM3'}));
s = serial('COM3','BaudRate',9600,'Terminator','CR/LF');
warning('off','MATLAB:serial:fscanf:unsuccessfulRead');
fopen(s);
muestras=1;
figure('Name','Captura');
xlabel('Tiempo')
ylabel('Aceleracion')
title('Acelerograma')
grid on
hold on
while 1<=n
ylim([0 240]);
xlim([0 0.5]);
valor=fscanf(s, '%f,%f')';
v2(muestras)=(valor(2));
v1(muestras)=(valor(1));
h=plot(v2(1:muestras),v1(1:muestras),'-')
drawnow
muestras=muestras+1;
delete(h)
end
fclose(s);
delete(s);
clear s;
end
  2 件のコメント
Erwin Avendaño
Erwin Avendaño 2019 年 12 月 2 日
The error was in the cycle, I was trying to graph data that was no longer there. I solved it like this:
Erwin Avendaño
Erwin Avendaño 2019 年 12 月 2 日
function arduinomatlab
v1=zeros(1,1000);
v2=zeros(1,1000);
delete(instrfind({'Port'},{'COM3'}));
s = serial('COM3','BaudRate',9600,'Terminator','CR/LF');
warning('off','MATLAB:serial:fscanf:unsuccessfulRead');
fopen(s);
muestras=1;
figure('Name','Captura');
xlabel('Tiempo')
ylabel('Aceleracion')
title('Acelerograma')
grid on
hold on
while 1
ylim([0 240]);
xlim([0 0.5]);
try
valor=fscanf(s, '%f,%f')';
v2(muestras)=(valor(2));
v1(muestras)=(valor(1));
plot(v2(1:muestras),v1(1:muestras),'-k')
drawnow
muestras=muestras+1;
catch
break
end
end
fclose(s);
delete(s);
clear s;
end

サインインしてコメントする。

採用された回答

Erwin Avendaño
Erwin Avendaño 2019 年 12 月 2 日
function arduinomatlab
v1=zeros(1,1000);
v2=zeros(1,1000);
delete(instrfind({'Port'},{'COM3'}));
s = serial('COM3','BaudRate',9600,'Terminator','CR/LF');
warning('off','MATLAB:serial:fscanf:unsuccessfulRead');
fopen(s);
muestras=1;
figure('Name','Captura');
xlabel('Tiempo')
ylabel('Aceleracion')
title('Acelerograma')
grid on
hold on
while 1
ylim([0 240]);
xlim([0 0.5]);
try
valor=fscanf(s, '%f,%f')';
v2(muestras)=(valor(2));
v1(muestras)=(valor(1));
plot(v2(1:muestras),v1(1:muestras),'-k')
drawnow
muestras=muestras+1;
catch
break
end
end
fclose(s);
delete(s);
clear s;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by