The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Dynamically Set Level2 M-S Function Dwrok Vector Dimension
Replies: 1   Last Post: Mar 18, 2013 11:43 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 83
Registered: 6/22/12
Dynamically Set Level2 M-S Function Dwrok Vector Dimension
Posted: Mar 18, 2013 10:17 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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? :-)

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2017. All Rights Reserved.