Index exceeds matrix dimensions plotting in GUI
Show older comments
Hello this callback function in the GUI is made to plot continously the values of 3 temperature sensors from the acquisition board. The acquisition board sends a large string containing data every 2 seconds.The string has comma's as parameter delimiters.I use strsplit similar to strtok to get "words" from the string ;i am interested in the words 1,4,7 which represent the temperature values.After i store them itransform them in double .After that i plot them and write the data in a file.I don't know why but i keep getting this timeout warning and this error:
**Warning: Unsuccessful read: A timeout occurred before the Terminator was reached. Index exceeds matrix dimensions.
Error in gui_3>read_btn_Callback (line 144) s2=(str2double(string(4)))/100;*
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in gui_3 (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)gui_3('read_btn_Callback',hObject,eventdata,guidata(hObject))*
function read_btn_Callback(hObject, eventdata, handles)
global myport;
handles=guidata(hObject);
handles.y0=zeros(handles.samples,1);
handles.y1=zeros(handles.samples,1);
handles.y2=zeros(handles.samples,1);
guidata(hObject,handles);
i=0;
a=fopen('Data.txt','wt');
while(strcmp(handles.port_stt,'opened'))
handles=guidata(hObject);
drawnow
handles.y0(1:end-1)=handles.y0(2:end,1);
handles.y1(1:end-1)=handles.y1(2:end,1);
handles.y2(1:end-1)=handles.y2(2:end,1);
if(strcmp(handles.port_stt,'opened'));
data_row=fscanf(myport,'%s');
string=strsplit(data_row,',');
guidata(hObject,handles);
s1=str2double(string(1));
s2=str2double(string(4));
s3=str2double(string(7));
handles.y0(end)=s1;
handles.y1(end)=s2;
handles.y2(end)=s3;
fprintf(a,strcat(data_row,'\n'));
end
plot(handles.axes1,0:handles.samples-1,handles.y0,'--','LineWidth',2,'Color','g');
grid(handles.axes1, 'on')
ylim(handles.axes1,[0 100]);
plot(handles.axes2,0:handles.samples-1,handles.y1,'--','LineWidth',2,'Color','g');
grid(handles.axes2, 'on')
ylim(handles.axes2,[0 100]);
plot(handles.axes3,0:handles.samples-1,handles.y1,'--','LineWidth',2,'Color','g');
grid(handles.axes3, 'on')
ylim(handles.axes3,[0 100]);
guidata(hObject,handles);
pause(0.0001);
end
fclose(a);
Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!