Matlab - Error guide

 
Vista:

Error guide

Publicado por Nelson (2 intervenciones) el 10/11/2016 18:24:23
Estoy haciendo una tarjeta de adquision de datos en matlab, que me envia y recibe datos de forma serial, al precionar un boton que inicie y otros 2 que al precionarlos, me envian un caracter por el ´puerto serial, pero me maqrco un error y no se el porque. a continuacion envio el codigo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
global s; %va ser la variable almacena la información del puerto
delete(instrfind({'Port'},{'COM11'})); %ajustar puerto serie!
%crear objeto serie
s = serial('COM11','BaudRate',9600,'Terminator','CR/LF');
warning('off','MATLAB:serial:fscanf:unsuccessfulRead');
%abrir puerto
fopen(s);  %el puerto se habilita para escuchar
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
% parámetros de medidas
tmax = 100; % tiempo de captura en s
rate = 1; % resultado experimental (comprobar)
 
 
 
% inicializar
v1 = zeros(1,tmax*rate);
v2 = zeros(1,tmax*rate);
v3 = zeros(1,tmax*rate);
v4 = zeros(1,tmax*rate);
 
i = 1;
t = 1;
k=1;
l=0;
q=zeros(1,4);
% ejecutar bucle cronometrado
tic
m=10;
%mat=[ones(4,5)]
 
while k<tmax
   t = 1+toc;
   t=round(t);
%     leer del puerto serie
    q(1) = fscanf(s,'%d %d %d %d');
     q(2) = fscanf(s,'%d %d %d %d');
      q(3) = fscanf(s,'%d %d %d %d');
       q(4) = fscanf(s,'%d %d %d %d');
      %  q(5) = fscanf(s,'%d %d %d %d');
 
    v1(t)=q(1)*5/1024;
    v2(t)=q(2)*5/1024;
    v3(t)=q(3)*5/1024;
    v4(t)=q(4)*5/1024;
 
 
    % dibujar en la figura 1
    x = linspace(0,t/rate,t);
    drawnow
    axes(handles.axes1)
    plot(v1(1:t),'r','LineWidth',2);
   % axis([t-5 t+2 0 5]); 
    grid on
 
    % dibujar en la figura 2
    x = linspace(0,t/rate,t);
    drawnow
    axes(handles.axes2)
    plot(v2(1:t),'r','LineWidth',2);
   % axis([t-5 t+2 0 5]); 
    grid on
 
    % dibujar en la figura 3
    x = linspace(0,t/rate,t);
    drawnow
    axes(handles.axes3)
    plot(v3(1:t),'r','LineWidth',2);
   % axis([t-5 t+2 0 5]); 
    grid on
 
 
    % dibujar en la figura 4
    x = linspace(0,t/rate,t);
    drawnow
    axes(handles.axes4)
    plot(v4(1:t),'r','LineWidth',2);
   % axis([t-5 t+2 0 5]); 
    grid on
 
 
%     
%     axes(handles.axes2)
%     plot(v2(1:t),'b','LineWidth',2);
%     axis([t-5 t+2 0 5]); 
%     grid on
 
 
end
 
 
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
global s;
while (1)
    valor='a'; %preguntar si aqui si deberia ir un while
    fwrite(s,valor)
 
end
 
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global s;
while(1)
    valor1='l';
    fwrite(s,valor1)
 
end



ERROR
>> ADQ
In an assignment A(:) = B, the number of elements in A and B must be the same.

Error in ADQ>pushbutton1_Callback (line 119)
q(1) = fscanf(s,'%d %d %d %d');

Error in gui_mainfcn (line 95)
feval(varargin{:});

Error in ADQ (line 43)
gui_mainfcn(gui_State, varargin{:});

Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)ADQ('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Royeth
Val: 3.309
Plata
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

Error guide

Publicado por Royeth (1818 intervenciones) el 10/11/2016 19:13:21
tienes que tratar de leer los datos antes para asegurarte del protocolo que maneja el puerto , si estás trabajando con arduino debes verificar que la información esté disponible y completa en el puerto .

Se trata de un problema de tiempo no siempre vas a tener la cadena de caracteres con un mismo valor y es ahí donde se presenta el desajuste de tamaño , así que debes asegurarte que la lectura sea homogenea , porque está mandando como varios valores al puerto y no puede asignarlos en una posición de un vector y por eso el error

saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar