Dynamic Variable with Two Values Inside a While Loop
显示 更早的评论
How to express a dynamic variable with two values or more inside a while loop:
An example of what I mean by a dynamic is a time of a job in a work shop at one of the machines so (Tij) T is for Time i is the job identification number, where i=(1,2,3) as an example j is the machine identification number, where j=(1,2,3,4,5,6) as an example
So when I say: T35 is the time of the 3rd job in the 5th machine. T11 is the time of the 1st job in the 1st machine. T35 & T11 can occur at the same time, let say both occurred when time = 1:00pm
My question how create a while loop that will finish all the three (3) jobs in all the six (6) machines. Also let say each machine takes 3 minutes to complete a job and it can only treat one job at a time.
I not sure if this dynamic variable can be an array or a structure or something else.
1 个评论
Read these:
And then learn to use indexing: faster, simpler, more robust, less buggy.
回答(1 个)
dpb
2017-1-15
0 个投票
Don't see that you need any loop at all. Simply populate a nJobMax by nMachines array with the appropriate start time values and accumulate total duration by column given the job duration as being fixed.
If the assignment is N jobs to the machine at one time to be processed sequentially, then it's even more trivial of just being that number*duration/job plus the starting time.
The new datetime class with duration variables should make this pretty simple to code.
6 个评论
Alaa Al-Saffar
2017-1-15
dpb
2017-1-15
Well, we can only answer the questions as asked. I wouldn't expect it to matter much on the other complications of how one might generate the actual elements in the array; one presumes this is some sort of MC simulation?
Alaa Al-Saffar
2017-2-22
dpb
2017-2-22
"what is MC Simulation"
Monte Carlo simulation...I was presuming probably you would be simulating a large number of these individual elements to evaluate from some distribution of job lengths to evaluate overall system statistics.
If the data are static as you show and TS(i+1)=TS(i)+D(i) for each job i, then I don't see how your expected TF(1)=6? If TS=1 and D=4, the TF=1+4 = 5 it would seem. Where's the other hour come from to get 6?
But, as I noted before
>> D=[4 7; 3 8; 4 7];
>> cumsum([1 1;D])
ans =
1 1
5 8
8 16
12 23
>>
is the cumulative end times from your above D; the start of the next is the end of the previous. Again, this is based on what you've described so far; the "how" to get the desired 6 instead of 5 for the first end time is insolvable from the description so far (unless it is just a typo???).
Alaa Al-Saffar
2017-2-23
编辑:dpb
2017-2-24
dpb
2017-2-23
Well, there are any number of examples of for loops, but the power in Matlab is in the vector operations. You'll probably want an outer loop for each of the trials, but look again at the solution above without looping that solves the time issue for all machines and all times for a given sampled duration dataset without needing any loops at all.
And, forget you've even heard of eval, there "there be dragons!" :)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!