Is there any data type equivalent for queue?

51 ビュー (過去 30 日間)
ROSHITH SEBASTIAN 2020 年 4 月 30 日
編集済み: 埃博拉酱 2022 年 4 月 5 日
Is there any data type which can handle FIFO queue operations?
I am using arrays to handle queues, but it has executional overhead since the size changes on each iteration. Now, I have to handle even array of queues, but it is getting complicated as each queue has different length at the end of each iteration. When I add an element in a row, the columns length of all the rows increases which makes it difficult to handle it.
Is there any efficient way to handle this situation. Even a link which discusses similar topics would be of great help.

回答 (2 件)

Guillaume 2020 年 4 月 30 日
The short answer is that no, unfortunately, there's no queue implemented in base matlab (there may be something hidden in one of the toolboxes but it's unlikely you'd be able to use it generically).
I would have a look at the fileexchange, there's probably several implementations of various quality. If there's nothing good enough there, I'd look at implementing it myself. A naive implementation would just grow/shrink an array as the queue fills/empties which indeed would be very innefficient in matlab (and most languages). A better implementation would grow the array in progressively larger chunks.
  4 件のコメント
Anubhav Kumar
Anubhav Kumar 2021 年 3 月 19 日
@Guillaume I have attached queue.m file in the same directory where my main.m file is present and I am trying to use queue but in main.m where I have written q = queue; on runnung the script error is thrwoing at q = queue.
please help me so that I can solve my issue.


埃博拉酱 2022 年 4 月 5 日
編集済み: 埃博拉酱 2022 年 4 月 5 日
As revealed by the package name, it can be shared among parallel workers.


Find more on Startup and Shutdown in Help Center and File Exchange





Community Treasure Hunt

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

Start Hunting!

Translated by