0

I am calling a Simulink simulation through a loop in Matlab. I am able to send many numerical parameters (initial conditions for integrators for example), but an error arises in my "From File" block.

I'm not quite sure how other people do it, but where I work we send it through a home-built function which takes a structure input. The fields of the structure are the variable names and the values of the fields are the variables themselves. for example:

pb = struct('preload',preload(pl_index),...
            'displacement',preload_displacement(pl_index),...
            'filename',fileList{m});

The 'preload' and 'displacement' variables evaluate fine, but the filename gives an error:

filename.mat

Does anyone know if you can pass the value of the variable filename (fileList{m}) in the 'From File' block and if so, how to do it. Thanks!

2
  • filename is used as a string parameter and is not evaluated as a variable. You would need to do set_param('from_file_block','filename',fileList{m}) for this to work. Commented Jul 6, 2017 at 14:21
  • Yes I agree, however with the script we're using at work I'm not sure if that would be possible... Good point though, thanks. @Navan Commented Jul 6, 2017 at 21:13

1 Answer 1

1

Answering my own question!

I used the Simulink "From Workspace" block instead of "From File".

f = load(fileList{m});
fnames = fieldnames(f);
% The files were arranged weird, so I have one field inside the structures... and they all had different names.
    switch fnames{1}
        case 'first'
            filedata = f.first;
        case 'second'
            filedata = f.second;
        case 'third'
            filedata = f.third;
        case 'fourth'
            filedata = f.fourth;
    end
    t = filedata(1,:);
    u = filedata(2,:);

loaded_file = timeseries(u,t);

And I pass loaded_file to my function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.