Please find below my code:
readdata=get(handles.uitable2,'data');
readdata=cellfun(@num2str, readdata, 'UniformOutput', false);
[nr,nb]=size(readdata);
for k=1:nr
disp(k)
disp(readdata(k,7))
if strcmp(readdata(k,7),'1')==1
readdata(k,:)='';
range=strcat('J',num2str(indexvec(k)+1));
xlswrite('cylinders record.xls','1','Record',range)
if strcmp(readdata(k,8),'1')==1
range=strcat('K',num2str(indexvec(k)+1));
xlswrite('cylinders record.xls','1','Record',range)
end
end
end
set(handles.uitable2,'data',readdata)
the problem is that i'm getting an error msg that the index exceeds the matrix even though i am making the loop knowing the size of the matrix!!!!
please note that the 7th and 8th column of readdata are of logical format (checkboxes)!!
i would like to add that when no checkbox is checked i don't face this problem, it only occur when a checkbox is checked

댓글 수: 5

Jan
Jan 2015년 11월 15일
편집: Jan 2015년 11월 15일
Please post a copy of the complete error message. Then the readers do not have to guess, in which line the error occurres.
Are you sure that the 7th and 8th column contain the strings '1' and not the value true?
Nagham Kabbara
Nagham Kabbara 2015년 11월 16일
편집: Nagham Kabbara 2015년 11월 16일
the error occurs at
Index exceeds matrix dimensions.
Error in unmoldingcyl>refresh_Callback (line 236)
disp(readdata(k,7))
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in unmoldingcyl (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)unmoldingcyl('refresh_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
and yes i am sure that the 7th and 8th columns contain either '1' or '0'. when i display the readdata array before entering the loop everything seems to be right. but after entering the loop the first row is not read properly
What is the value of k when the error happens?
Can you add
assert(nb >= 8, 'not enough columns in the cell array')
before the loop and check that the assert does not get triggered?
As an aside, completely unrelated to your problem, why are you converting numbers to strings to then do slow string comparisons when number comparisons are fast? Also, strcmp(x, y) == 1 can be simply strcmp(x, y), the == 1 is just the identity operation. Finally, the normal way to delete a row is by assigning []. Assigning an empty string, '', works, but it's unusual and since there's no comment, begs the question: did you really mean that?
Nagham Kabbara
Nagham Kabbara 2015년 11월 16일
the error happens for k=nr-1.
i am converting the num to str because i am unable to read them as numbers (the 0 and 1 are equivalent to false and true, result of checking and unchecking the checkboxes)
Nagham Kabbara
Nagham Kabbara 2015년 11월 16일
i found the problem guys!!!!!
everytime a '1' is found the row is deleted and the array changes of size.
thank you all for your help

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2015년 11월 15일

댓글:

2015년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by