0

Apparently Simulink supports only few datatypes.

So, how to keep something other? I want to produces images from a directory, how to keep directory list and current position?

The following code causes error

function DoPostPropSetup(block)

  block.NumDworks = 1;

  block.Dwork(1).Name            = 'Filelist';
  block.Dwork(1).Dimensions      = 1;
  % block.Dwork(1).DatatypeID      = -10;      % MATLAB Array  % does not work
  block.Dwork(1).DatatypeID      = 0;      % double
  block.Dwork(1).Complexity      = 'Real'; % real
  block.Dwork(1).UsedAsDiscState = true;

  block.Dwork(1).Data = dir(block.DialogPrm(1).Data);
Jason S
  • 184,598
  • 164
  • 608
  • 970
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385

1 Answers1

1

You cannot store non-numeric types in level-2 s-function Dwork. For your use, you may need to convert your list of files to a character string with a path separator and use char type to store it. You need a different Dwork to store the position.

Another approach is to store the list as char matrix with smaller file names padded with spaces or any character which is not part of valid file name. Storing as matrix will make it easier to index into the list.

Navan
  • 4,407
  • 1
  • 24
  • 26
  • Incredibly complex. Currently I am storing in model workspace variables. This way disadvantages is that it is model-wise. – Suzan Cioc Jul 17 '13 at 14:41
  • P.S. char type is also not allowed in DWork as I found. so I need to have enormous conversion efforts each cycle.... incredible! – Suzan Cioc Jul 17 '13 at 14:42
  • If your list is same modelwide you can also use persistent variable inside your function. – Navan Jul 17 '13 at 17:42
  • 1
    block consists of multiple functions. – Suzan Cioc Jul 17 '13 at 17:44
  • persistent variable can reside in a common sub-function called by multiple functions – Navan Jul 18 '13 at 12:56
  • Ok, but I guess this will be wider than a model-scope. Variables will be the same in all blocks in all models. – Suzan Cioc Jul 18 '13 at 13:12
  • Is it possible to store variables at block scope somehow? I can create a `hashmap` at model level, but this is very complex... – Suzan Cioc Jul 18 '13 at 14:06
  • 2
    Each block has a UserData field where you can store any value. See http://www.mathworks.com/help/simulink/ug/associating-user-data-with-blocks.html – Navan Jul 19 '13 at 13:53
  • cool! what if I want to store several parameters? How to store `struct` there? May I change individual fields of a structure, stored in `UserData`? – Suzan Cioc Jul 21 '13 at 17:08
  • apparently I should `get` my param before use, and then `set` it back after modification... very ugly – Suzan Cioc Jul 21 '13 at 17:24
  • It's not that ugly actually. It may seem like it at first; think of it as a safe deposit box where there's a little overhead to retrieve and replace the container, but then you have freedom to put just about anything in it (including a MATLAB structure or handle to a class object) – Jason S Nov 07 '13 at 20:55