d-hug
d-hug

Reputation: 55

replacing blocks in matlab

i know this might be very simple, but i'm stuck for an hour at least.. I just cannot find out what the mistake is.( I read the docu) Any help is appreciated. Thanks in advance

function y = in_out_modeling(~)

    model_name = 'modeladvisor_test';

    all_input_blocks = find_system('modeladvisor_test', 'FollowLinks', 'on', 'LookUnderMasks', 'all', 'BlockType', 'In');
    all_output_blocks = find_system('modeladvisor_test', 'FollowLinks', 'on', 'LookUnderMasks', 'all', 'BlockType', 'Out');

    for i=1:length(all_input_blocks)
        replace_block(model_name, all_input_blocks(i), 'From');
    end

    for i=1:length(all_output_blocks)
        replace_block(model_name, all_output_blocks(i), 'Goto');
    end

Upvotes: 0

Views: 2401

Answers (2)

Phil Goddard
Phil Goddard

Reputation: 10772

There are no blocks with BlockType of In or Out. Hence all_input_blocks is empty and you are not calling any of the replace_block code. Similarly for the outputs.

Upvotes: 1

Navan
Navan

Reputation: 4477

replace_block replaces blocks by taking their BlockType as input. You are sending the path for those blocks as input which would not work. Try using,

replace_block(model_name, 'Inport', 'From')

The above will prompt you for each replacement. If you do not want to be prompted, use

replace_block(model_name, 'Inport', 'From', 'noprompt')

replace_block also will return the paths of the new blocks it inserted. You can use that list to verify whether you have all your blocks replaced.

If you would like to do your own search using find_system, then use 'Name' as an argument to replace_block.

replace_block(model_name, 'Name', all_input_blocks(i), 'From', 'noprompt')

Upvotes: 1

Related Questions