How to continuely index a cell in a loop

조회 수: 1 (최근 30일)
Cassidy
Cassidy 2015년 4월 16일
편집: Jan 2015년 4월 16일
I am trying to create and inventory that continues to index the second column everytime it runs throught the loop. It is apart of a pushbutton call back so that everytime it is clicked it is suppose to run through the loop. It will run through but it stops indexing even after I click the push button multiple times.
function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
global G
if (exist('Inventory1.mat','file') == true)
load('Inventory1.mat')
found = false
for InventoryIndex= 1: size(Inventory1,1)
if compare(G,Inventory1{InventoryIndex,1})
%if match we found a match and need to increment how many we have
%fou
Inventory1{InventoryIndex,2} = Inventory1{InventoryIndex,2} + 1
found= true
else
%keep looking
end;
end;
if (found== false)
if (InventoryIndex == size(G,1))
Inventory1{InventoryIndex + 1, 1} = G
Inventory1{InventoryIndex + 1, 2} = 1
end;
end;
else
Inventory1{1,1}= G
Inventory1{1,2}= 1
end;
save('Inventory1.mat','Inventory1')
  댓글 수: 1
Jan
Jan 2015년 4월 16일
편집: Jan 2015년 4월 16일
exist('Inventory1.mat','file') == true is not correct. exist() does not answer true or false but a number from 0 to 8. So better use: exist('Inventory1.mat','file') ~= 0 .
What is the problem of your code?

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by