Filter löschen
Filter löschen

Hi I hope are well, I am making a serial interface for communication between C and matlab Pic by Proteus, but I get this error because it can be?

1 Ansicht (letzte 30 Tage)
??? Attempted to access c(1); index out of bounds because numel(c)=0.
Error in ==> trabajopractico at 139 y(contador_ECG)=(c(1))*5/1024; and the code:
function trabajopractico(numero_Muestras)
close all;
clc;
n=207300;
y=zeros([1 n]); %%Vector donde se guardaran los datos
for i = 1:n, y(i) = i; end
delete(instrfind({'Port'},{'COM1'}));
PIC16F877A=serial('COM1'); %%vector para la comunicación serie
PIC16F877A.BaudRate=9600; %%velocidad en baudios
PIC16F877A.DataBits=8; %%Bits de datos igual a 8
PIC16F877A.StopBits=1; %%un bit de parada
warning('off','MATLAB:serial:fscanf:unsuccessfulRead');
fopen(PIC16F877A); %%Abre el puerto
contador_ECG=1;
msgbox('Recibiendo Señal ECG...');
%%Ventana para la Grafica PROTEUS:ECG
figure('Name','PROTEUS: SEÑAL ECG');
title('PROTEUS: SEÑAL ECG');
xlabel('Número de Muestras');
ylabel('Amplitud');
grid;
%%Bucle While para que tome y grafique las Muestras
while contador_ECG<=numero_Muestras
ylim([0 5.1]); %Limites del eje y
xlim([contador_ECG-20 contador_ECG+200]); %Limites del eje x
c=fscanf(PIC16F877A,'%d')'; %Toma el valor recibido por el puerto y lo guarda en la variable
y(contador_ECG)=(c(1))*5/1024;
plot(contador_ECG,y(contador_ECG),'X-r'); %Grafica el potencial_A
drawnow
contador_ECG=contador_ECG+1;
end
%%Cerrando el Puerto...
fclose(PIC16F877A);
delete(PIC16F877A);
clear all;

Antworten (1)

Stalin Samuel
Stalin Samuel am 11 Jun. 2016
  • The variable 'c'not having even a single element
  • Make sure that 'c' receive the signal from Pic
  1 Kommentar
NiyuB
NiyuB am 12 Jun. 2016
thanks, good that the c variable must be in the programming of Pic c, is what you say? really I could not fix it, that error may be because since the pic is not receiving?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by