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 8422949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:35:54+00:00 2026-06-10T03:35:54+00:00

I have encountered a problem. I have to use MATLAB with linux. I need

  • 0

I have encountered a problem. I have to use MATLAB with linux.
I need to parse data from MATLAB to Linux and vice versa.

For exammple

This all is writtein in

basic.sh

this basic.sh has to be opened in MATLAB

 s=3     # is defined is MATLAB
##########################


for (( p=1 ; p<5; p++ ))     # from here starts the loop in Linux
do                                # is a command from Linux
echo "$p"                         # is a command from Linux
add= $p+s                         # should calulate in linux , is a command from Linux
add=add/5                         # should do in MATLAB 
done     

#########################
 add                              # should OUTPUT the value of add as there is no semicolumn in MATLAB 

Kindly suggest me a possible way for such a small example the rest I will expand it myself.

best regards

  • 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-10T03:35:55+00:00Added an answer on June 10, 2026 at 3:35 am

    Well, you can call Matlab from a terminal, and run a single command:

    $ matlab -nodesktop -nojvm -nosplash -r <YOUR_COMMAND>
    

    in which <YOUR_COMMAND> can be an m-script/function. The output of this can be redirected into shellscripts,

    $ matlab -nodesktop -nojvm -nosplash -r <YOUR_COMMAND> | ./basic.sh
    

    (your script should be capable of handling pipes), or this entire command can be embedded in shell scripts,

    #!/bin/bash
    
    s=$(matlab -nodesktop -nojvm -nosplash -r <FUNCTION_GENERATING_S>)
    
    <code generating $add>
    
    result=$(matlab -nodesktop -nojvm -nosplash -r <SOME_FUNCTION($add)>)
    

    You can of course also resort to using files as memory. Matlab part:

    s=3;      
    
    fid = fopen('TMP.txt','w');
    fprintf(fid, s);
    fclose(fid);
    
    !./basic.sh
    
    fid = fopen('TMP.txt','r');
    add = fscanf(fid, '%f');
    fclose(fid);
    

    Shell script:

    #!/bin/bash
    
    s=$(cat TMP.txt)
    for (( p=1; p<5; p++ ))     
    do                            
        echo "$p" 
        add=$(($p+$s))
        add=add/5                      
    done
    
    echo $add > TMP.txt
    

    Advantage of this is that there is a strict separation between Matlab and shell script, and only one m-file will suffice.

    Of course, whichever way you choose — why would you want to do this in the first place? Matlab can do most of what bash is capable of, and is also platform independent (so if you switch to MS Windows, it all still works)…so can you clarify this a bit?

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

Sidebar

Related Questions

I have encountered this problem: Depending on numbers from I want to create a
I have encountered a problem with creating a thumbnail from an uploaded image file,
I have encountered a problem of placing data into the Table View. Here is
I have encountered this problem today and I don't have an explanation for it.
I have encountered this problem a few times, and am not able to figure
This is a problem I have encountered several times over the years, and I
I have encountered a problem. When I use jQuery to load a page that
I recently updated from mathematica 7.0 to 8.0, and have now encountered problem with
I use VS2010 and I have encountered following problem: HWND handle = NULL; handle
I am developing a web app and have encountered a problem. I need to

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.