Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8901923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:28:56+00:00 2026-06-15T01:28:56+00:00

I try to create a matlab file that can run a simulink model. But

  • 0

I try to create a matlab file that can run a simulink model.
But has problem with send data from MATLAB into the simulink model.
In the model I has Import Block that I want send my in stream of data from matlab.

My Current code of matlab is.

function result = CallSimulinkModel(modelName, timeStep, inputMatix, key)
    if(timeStep<=0) 
        error('MATLAB:CallSimulinkModel','Timestep is lower or equal with 0');
    end
    endTime = max(size(inputMatix))*timeStep;
    result = SubCallSimulinkModel(modelName, 0:timeStep:endTime, inputMatix, key);
    %OutVector.const = inConst;
end

function [result,constants] = SubCallSimulinkModel(var_model,time_var,inputMatix, K)
    var_setting = simset(...
        'SrcWorkspace','current'... 
    );
    % How to feed the sim model with the data from input matrix as Inport
    % 1, Inport 2, ...?
    [~,~,result] = sim(var_model, time_var, var_setting);
    constants = K;
end

And the model is Simulink Model

I has no problem with get the result from the simulink or set the constants K.in1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:28:57+00:00Added an answer on June 15, 2026 at 1:28 am

    Found a working solution.

    % For MATLAB R2012a
    function [result,time] = RunSimulinkModel(modelName, timeStep, inputMatix, key)
        if(timeStep<=0) 
            error('MATLAB:RunSimulinkModel','Timestep is lower or equal with 0');
        end
        endTime = max(size(inputMatix))*timeStep-timeStep;
    
        %CCC = [time_var;D]'
        % Is a 2 or more column that the first column is a time vector that
        % hold all time and the other columns hold the data.
        dataMatrix = [0:timeStep:endTime;inputMatix]';
    
        [result,time] = RunSimulinkModelSub(modelName, timeStep,dataMatrix,key);
    
    end
    
    function [result,time] = RunSimulinkModelSub(var_model,var_steptime, D,K)  %#ok<INUSD>
        var_setting = struct(...
            'SrcWorkspace','current',... 
            'SaveTime','on','TimeSaveName','tout', ...
            'SaveOutput','on','OutputSaveName','yout', ...
            'LoadExternalInput', 'on', 'ExternalInput', 'D',...
            'FixedStep', 'var_steptime' ...
        );
        var_row_result = sim(var_model, var_setting);
        result = var_row_result.get('yout');
        time = var_row_result.get('tout');
    end
    

    The 'LoadExternalInput', 'on', 'ExternalInput', 'D',... will tell the model to use
    data from D as time-vector and data-vector.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can call J48 from MATLAB with no problem. But when I try the
snippet from The Server code : public void run() { try { // Create
I have a method that that creates a MatLab array name from a file
I try create a map for open ~/.vimrc, but open the ~/.vimrc only when
I try to create styles with first-child and last-child items but I encountered a
I try to create my own linux bash script that calls truecrypt for mounting.
I try to create the simplest WinAPI window using assembly NASM. I have problem
I try to create a new file inside a JSP and try to save
I try to create a thread in QT, can declare, create and start it,
try { // Create an appending file handler boolean append = true; FileHandler handler

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.