現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
FIFO push all values as vector
5 ビュー (過去 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 件)
参考
カテゴリ
Help Center および File Exchange で Sources についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)