Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
Tiger
Posts:
43
Registered:
6/22/12
|
|
Dynamically Set Level2 M-S Function Dwrok Vector Dimension
Posted:
Mar 18, 2013 10:17 AM
|
|
Hi all,
How can I make the dimension of a Dwrok Vector depend on the value (not width) of an InputPort. My InputPort is uint8(FileName.txt) which is a value passed from a Constant block which, in turns, are updated externally via an m-file.
I want to be able to do the following: FileName = char(block.InputPort(3).Data); % Reversing it back to a 'string'. text_lines = (length(dataread('file', FileName, '%s', 'delimiter', '\n'))) + 1; % Counting number of rows in a text file, which is my desired Dimensions value for DworkVector(1). block.Dwork(1).Dimensions = text_lines; block.Dwork(1).Data = zeros(1, text_lines);
The 'FileName' and 'text_lines' syntax work well in other Level2 M-S Functions in my model where I don't require upating any Dimensions values. However, here, I want Dwork(1).Dimensions to be equal to a value that comes with InputPort(3) i.e. after applying char() on it.
I've tried running those commands at SetInpPortDims(block, idx, di), DoPostPropSetup(block), Start(block), Outputs(block). I get an error saying "file not found or permission denied." I've had a similar error before, but the mistake was referring to the wrong InputPort when applying char().
Any ideas? :-)
|
|
|
|