- The variable 'c'not having even a single element
- Make sure that 'c' receive the signal from Pic
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 visualización (últimos 30 días)
Mostrar comentarios más antiguos
??? 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;
0 comentarios
Respuestas (1)
Stalin Samuel
el 11 de Jun. de 2016
Ver también
Categorías
Más información sobre Data Import and Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!