Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Why does it tell me that it exceeded the array? if you have more than what it supports in graphics?
조회 수: 5 (최근 30일)
이전 댓글 표시
Why does it tell me that it exceeded the array? I don't understand if I put more than 1000
I leave the error message that matlab tells me
<<<Error message>>>
Index exceeds matrix dimensions.
Error in arduinomatlab (line 29)
v1(muestras)=(valor(1));
<<Error message>>
<<CODE>>
function arduinomatlab
global v1 v2
v1=zeros(1,100000);
v2=zeros(1,100000);
n=10;
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('Muestras')
ylabel('Voltaje (V)')
title('Captura de voltaje en tiempo real con Arduino')
grid on
hold on
while muestras<=n
ylim([0 15]);
xlim([muestras-10 muestras+10]);
valor=fscanf(s, '%d,%d')';
v1(muestras)=(valor(1));
v2(muestras)=(valor(2));
plot(muestras, v1(muestras),'*-b');
plot(muestras, v2(muestras),'*-r');
drawnow
muestras=muestras+1;
end
fclose(s);
delete(s);
clear s;
end
댓글 수: 0
답변 (1개)
Walter Roberson
2019년 12월 2일
max_error = 10;
error_count = 0;
while muestras<=n && error_count < max_error
ylim([0 15]);
xlim([muestras-10 muestras+10]);
thisline = fgetl(s);
valor = sscanf(thisline, '%d,%d')';
if length(valor) < 2
error_count = error_count + 1;
fprintf('warning #%d, line with unexpected content: "%s"\n', error_count, thisline);
else
v1(muestras)=(valor(1));
v2(muestras)=(valor(2));
plot(muestras, v1(muestras),'*-b');
plot(muestras, v2(muestras),'*-r');
drawnow
muestras=muestras+1;
end
end
if error_count >= max_error
fprintf('Gave up because of too many errors on input\n');
end
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!