Info

This question is closed. Reopen it to edit or answer.

How to place and download in a loop?

1 view (last 30 days)
Emilia
Emilia on 5 Jul 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
Hello everyone,
I have a number of boxes that I need to store them in a storage area (1X10), number 1 Its boxes inside cells and zeros is empty.
i
Example:
NumberOfBoxes=10
StorageArea=[1,1,1,0,0,0,0,0,0,0] (the boxes shown here have remained from yesterday)
Placing boxes into storage area, downloading a number of boxes and creating a vector that updates information about the quantity of boxes each time.
i
StorageArea=[1,1,1,1,1,1,1,1,1,1]
NumberOfBoxes=3
i
Create information from a number of boxes in StorageArea to Vector:
Vector=[10]
i
After vector information,The area will be empty :
StorageArea=[0,0,0,0,0,0,0,0,0,0]
Again boxes are placed here each time.
StorageArea=[1,1,1,0,0,0,0,0,0,0]
Vector=[10,3]
I have some mistakes in the code, My code:
i
Vector=[]
for x=1:NumberOfBoxes
count=0
for w=1:length(StorageArea)
if StorageArea(w)==0
StorageArea(w)=1
count=count+1
NumberOfBoxes=NumberOfBoxes-count %Downloading a number of boxes
if 10==length(StorageArea(StorageArea==1))
n=10
Vector=[boxes1new,n]
StorageArea=zeros(StorageArea)
else
BoxesEnd=length(StorageArea(StorageArea==1))
Vector=[boxes1new, BoxesEnd]
end
end
end
end
Thanks in advance.
  4 Comments
Dennis
Dennis on 5 Jul 2018
Here is a version with one loop:
NumberOfBoxes=3;
StorageArea=[1,1,1,0,0,0,0,0,0,0];
Vector=[10,3];
while NumberOfBoxes > 0
idx=find(StorageArea==0);
if isempty(idx)
Vector=[Vector,numel(StorageArea(StorageArea==1))];
StorageArea(:)=0;
else
StorageArea(idx(1))=1;
NumberOfBoxes=NumberOfBoxes-1;
end
end
Vector=[Vector, numel(StorageArea(StorageArea==1))];
Emilia
Emilia on 5 Jul 2018
Thank you very much!
I learned new things from you :)

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!