이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
FIFO push all values as vector
조회 수: 4 (최근 30일)
이전 댓글 표시
Tamar
2023년 7월 11일
Hi, I want to pop the fifo every step time (1 sec) and push all the values as vector every 5 steps (5 sec). I didn’t find way to push more then one value every step time
채택된 답변
Jon
2023년 7월 11일
I assume you are using the Queue block in the DSP System Toolbox in Simulink.
If so you should supply the In port with a 5 element vector input, then supply the Push port with the output of Pulse Generator with 5 second period, and the Pop port with the output of a Pulse Generator with a 1 second period.
You may want to delay the start of popping until the buffer is full.
See my attached example
댓글 수: 20
Tamar
2023년 7월 11일
I can’t open your example because I have 2022.
Anyway, how can I do from one signal vector that it’s value are - [1sec, 2sec, 3sec…]?
And what if I want the push be variable? Than I can’t pop the fifo a vector because I don’t know the size that the vector should be
Jon
2023년 7월 11일
Please explain in detail what you are trying to accomplish, ideally with example input and output
Tamar
2023년 7월 11일
I have pulses. Let’s say my step time is 1 sec and all the simulation run 30 sec. My source is something that make pulses. I don’t know the time for each pulse. I would like to get the values for each pulse to Matlab function block. For example: My source is [0 0 3 6 10 6 3 0 0 5 6 10 6 5 0 6…] (every value is one step time) I want to input to Matlab function block one time [3 6 10 6 3] and the second time [5 6 10 6 5]… - do a vector and cut it according the zeros value each pulse
Jon
2023년 7월 11일
What will your Matlab function block output while it is waiting for the first 5 non-zero values? What will it output while it waits to accumulate the next 5 non-zero values?
What is the bigger context here, do you really have to do this in Simulink, or do you have data in a file that could just be processed using MATLAB?
Tamar
2023년 7월 11일
I wish I could do it without simulink but My data is create in simulink and I use simulink blocks also after the Matlab function block, and the time line is important.
I can triggered the Matlab function block according the value of the pulse (if the memory is above zero and the current value is zero), and then don’t use it when I don’t have enough values. I don’t really care if the Matlab function block get inputs all the time steps and output nan values while the input is nan or zero.
Jon
2023년 7월 11일
Will the data of interest alway come as 5 consecutive non-zero values followed by some zeros, or sometimes are there zeros between the values that must be discarded until you accumulate 5 non-zero values, so is it always like your example, or could it be
[0 0 3 6 0 10 6 3 0 0 5 6 10 0 0 6 5 0 6…] (every value is one step time) input to Matlab function block one time [3 6 10 6 3] and the second time [5 6 10 6 5]?
Tamar
2023년 7월 11일
No. Every zero value is new pulse. It’s not always five values of numbers. It’s could be [ 0 3 6 3 0 0 0 5 6 10 6 5 0 1 0 0] and the input to Matlab function block is [3 6 3] and then [5 6 10 6 5] and then [1].
I tried to use buffer block but in this block I have to set size.
Moreover, I tried to use to file block and from file block and restart the file when I want but it’s impossible to use to file block and from file block that have the same name.
Jon
2023년 7월 12일
I think this approach may work for you. I have use a tapped delay line to buffer the values. I detect a zero following a non-zero pulse train (e.g. the zero following 3 6 3 in your example). When I detect this zero, I trigger a triggered subsystem that hold the MATLAB function block. and receives the entire contents of the FIFO (output of the tapped delay line). Inside the function block I extract just the most recent pulse train, with some additional logic, and the compute the desired function of the pulse train values.
I have attached the model demonstrating this saved as version 2022a. Hope you can open and run it Also here is a screen shot for an overview. Below is the code inside of the MATLAB function block.
Note this approach won't find a final non-zero pulse train at the end of the simulation unless the last element in the input is a zero, so you may have to be careful about that edge case.
function y = fcn(u)
% function to do demonstrate doing something
% with group of pulse inputs
% u is output of tapped delay line, which essential acts as FIFO buffer
% Function is executed at end of non-zero pulse train, since u is entire
% contents of FIFO, and non-zero pulse trains are variable length, there
% may be some previous pulse trains and/or zeros in the buffer
% Just keep the newest non-zero values
idx = find(u==0,1,'last');
% Note even though idx has only one element, it seems that Simulink doesn't
% know this and has errors unless you just use the first element of this
% one element vector, so use idx(1), rather than idx
iStart = idx(1) + 1;
x = u(iStart:end,1); % just the most recent pulse train
% Calculate something using the non-zero pulse train, I will compute the
% total, but you can insert what you want here
y = sum(x);

Jon
2023년 7월 12일
If you have Stateflow, you could also implement something in there to handle this type of behavior.
Tamar
2023년 7월 13일
Sorry I didn’t reply, I wasn’t near computer. I don’t know why but I still can’t open it. Can you please send a screenshot of the simulation?
Tamar
2023년 7월 17일
It’s working, thank you!
Another question - how can I do the same to vectors? I have fixed size vector [1 14] every x second (according the pulses) and I want all the vector of 10 seconds for other Matlab function. It’s impossible to do tapped delay to vector :(
Jon
2023년 7월 17일
I'm not understanding the situation with the vectors. Please explain in detail what you are trying to do with the vectors.
Tamar
2023년 7월 17일
Every pulse input to Matlab function and the output is vector [1 14].
I want to do matrix for all the vectors that receive during 10 seconds
Tamar
2023년 7월 17일
I replace your Matlab function with this function:
function y = fcn(u)
idx = find(u==0,1,'last');
iStart = idx(1) + 1;
x = u(iStart:end,1)'; % just the most recent pulse train
y = zeros(1,10);
y(1,1:length(x)) = x.*2;
end
and write it to the workspace in the triggered subsystem.
I got a time of [7,14,16,21,23,28] and the vector of eatch:
7: [2, 4, 6, 8, 10, 12, 14, 0, 0, 0]
14: [10, 12, 20, 12, 10, 0, 0, 0, 0, 0]
16: [12, 0, 0, 0, 0, 0, 0, 0, 0, 0]
21: [2, 4, 0, 0, 0, 0, 0, 0, 0, 0]...
Now I want the vectors of any 10 seconds will be in matrix:
1) [2, 4, 6, 8, 10, 12, 14, 0, 0, 0]
2) [10, 12, 20, 12, 10, 0, 0, 0, 0, 0; 12, 0, 0, 0, 0, 0, 0, 0, 0, 0]...
I don't care if the time step of the matrix be the last time in the 10 seconds (16 in case 2) or the first (14)
Jon
2023년 7월 18일
I think the attached model will do what you are asking for. Here is a screenshot too.

Tamar
2023년 7월 18일
I tried to not use buffer. I did something and I think it worked. Thank you anyway, you help me a lot!!
Jon
2023년 7월 18일
Hi Glad you found a solution. I and maybe others would be interested to see your approach without a buffer. Could you attach a simple model that demonstrates the idea.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
