简体   繁体   中英

Matlab script execution from bash

I am able to execute the following from terminal :

matlab -nojvm < span.m

This works fine and produces the required output.

However, in the same directory, if I write a bash script:

#!/bin/bash


matlab -nojvm < span.m

I get the following error when I execute it:

wallShearStresswallsconstant=importdata("wallShearStress_wallBottom.raw");
                                         |
Error: The input character is not valid in MATLAB statements or expressions.
 Undefined function 'wallShearStresswallsconstant' for input arguments of type
'double'.

Please let me know what I am doing incorrectly.

The matlab script is as follows and it reads a file (wallShearStress_wallBottom.raw) with 6 columns and 45288 rows (all numbers), for testing purpose dosent matter what numbers are there.

clear all 
clc
wallShearStresswallsconstant=importdata("wallShearStress_wallBottom.raw");
ly=110;%64; %nz
lx=407;%239;%nx
ShearStress=zeros(lx,5);
%Uinf=15.894579;
Uinf=16.77;
i=1;
j=1;
k=1;

while i<lx+1
    while j<ly+1
        ShearStress(i,1)=wallShearStresswallsconstant(k,1);
        ShearStress(i,2)=wallShearStresswallsconstant(k,2);
        ShearStress(i,3)=wallShearStresswallsconstant(k,3);
        if wallShearStresswallsconstant(k,4) < 0
            ShearStress(i,4)=ShearStress(i,4)+1;
        else
            ShearStress(i,5)=ShearStress(i,5)-1;
        end
        j=j+1;
        k=k+1;
    end
    j=1;
    i=i+1;
end

SS = ShearStress;
SS(:,5) = SS(:,4)-SS(:,5);
SS(:,4) = SS(:,4)./SS(:,5);
plot(SS(:,1),SS(:,4))
SS = SS';

fileID = fopen('new.txt', 'w');
fprintf(fileID,'%f %f %f %f %f\n',SS);

Please use the following code instead:

importdata('wallShearStress_wallBottom.raw');

And the common bash command for executing matlab script file is like this:

matlab -nodisplay -nojvm -nosplash -nodesktop -r \
    "try, span, catch, exit(1), end, exit(0);"

where span is your .m filename.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM