Azzera filtri
Azzera filtri

Question about S function

2 visualizzazioni (ultimi 30 giorni)
Owen
Owen il 10 Ott 2012
Hi,
Is it possible to realize the following with Level 2 S function?
The input is a binary data, that is, every time only one bit can be read. The output shall save up to 10 bit and give them out. In this case the sample times at the input and at the output are different.
The problem is, in S function "block.InputPort(1).Data" is only valid for the current sample time.
Thanks Senmeis

Risposta accettata

Kaustubha Govind
Kaustubha Govind il 10 Ott 2012
You need to create DWork vectors for the S-function to store all previous inputs.

Più risposte (1)

Owen
Owen il 11 Ott 2012
Thank you.
With your advice I write the following code:
function DoPostPropSetup(block)
block.Dwork(1).Dimensions = 10;
function Update(block)
number = 1;
if number <= Block.Dwork(1).Dimensions
block.Dwork(1).Data(number) = block.InputPort(1).Data;
number = number + 1;
end;
function Outputs(block)
block.OutputPort(1).Data(1:block.Dwork(1).Dimensions) = block.Dwork(1).Data;
But it seems that only the first element of “Block.OutputPort(1).Data” is assigned. That is, “Block.OutputPort(1).Data” doesn’t wait for 10 elements before outputting. Do I need a flag to signal the status as used in C?
Thanks Senmeis
  3 Commenti
Owen
Owen il 13 Ott 2012
I tried the following code:
function DoPostPropSetup(block)
block.Dwork(2).Dimensions = 1;
block.Dwork(2).DatatypeID = 0;
block.Dwork(2).Complexity = Real;
function Start(block)
block.Dwork(1).Data = zero(block.Dwork(1).Dimensions, 1);
block.Dwork(2).Data = 1;
function Update(block)
if block.Dwork(2).Data <= block.Dwork(1).Dimensions
block.Dwork(1).Data(block.Dwork(2).Data) = block.InputPort (1).Data;
block.Dwork(2).Data = block.Dwork(2).Data + 1;
else
block.Dwork(2).Data =1 ;
end;
The idea is, data of different samples is stored in Block.Dwork(1).Data and number of samples is stored in Block.Dwork(2).Data, but I encountered an error:
“Subscript indices must either be real positive integers or logicals.”
for this line:
block.Dwork(1).Data(block.Dwork(2).Data) = block.InputPort(1).Data;
I also tried the following variants but it doesn’t help.
block.Dwork(2).DatatypeID = 1;
block.Dwork(2).DatatypeID = 2;
block.Dwork(2).DatatypeID = 3;
block.Dwork(2).DatatypeID = 4;
block.Dwork(2).DatatypeID = 5;
What is wrong with it?
Thanks Senmeis
Kaustubha Govind
Kaustubha Govind il 16 Ott 2012
Owen: You cannot change the size of DWork vectors at runtime. It is best to initialize it to a vector of 10 zeros and gradually fill it in.

Accedi per commentare.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by