Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

How to place and download in a loop?

1 visualización (últimos 30 días)
Emilia
Emilia el 5 de Jul. de 2018
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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 comentarios
Dennis
Dennis el 5 de Jul. de 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 el 5 de Jul. de 2018
Thank you very much!
I learned new things from you :)

Respuestas (0)

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by