필터 지우기
필터 지우기

Is there any data type equivalent for queue?

조회 수: 70 (최근 30일)
ROSHITH SEBASTIAN
ROSHITH SEBASTIAN 2020년 4월 30일
댓글: Melih Furkan SEN 2023년 11월 3일
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.

답변 (3개)

Guillaume
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
ROSHITH SEBASTIAN
ROSHITH SEBASTIAN 2020년 5월 11일
편집: ROSHITH SEBASTIAN 2020년 5월 11일
Thank you sharing the implementation.
I tried to realizre queues wth this approach(not array of queues, but only queues), but it consumed more time than using arrays to realise queue. The simulation duration for 3 repetitions are given below:
Using array for queue : 53.267074, 79.400834, 66.493679 seconds
Using attached file : 147.340302, 96.339909, 98.572212 seconds
I have not implemented the array of queues section of the simulator. I will try both the option and see which would be better for the simujlator as a whole.
Anyways, thanks you so, much for the effort. It might be needed in other efforts or maybe in this if it outperforms for the scenario of array of queues.
*Note : Adding 5000 elements and dequeueing them takes 0.363806 seconds in my machine, hence I think the issue is the function calls and other transfer of data using this approach
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일
parallel.pool.PollableDataQueue
As revealed by the package name, it can be shared among parallel workers.

Mahendra
Mahendra 2023년 8월 9일
Instead of resizing arrays during execution, you can initialize them with zeros up to a generous length. This way, you avoid frequent size adjustments and can simply track the relevant data within this pre-allocated space.
I frequently do this and found it to not have any speed penalties. We are wasting RAM but rarely are a problem on modern day PCs.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by