MATLAB Answers

Ask about matlab code line by line

14 views (last 30 days)
I want to know the meaning of the MATLAB code line by line
command_output_1 =ssh2_simple_command(hostname,username,password,'grep
-h "mat water" ./RBWR_TB2_2019/RBWR_TB2_2019');
this line mean login to server and find the line with "mat water" and give that line equal to command_output_1, Am I right?
for m = 1:length(command_output_1)
Y1(m,1) = textscan(command_output_1{m},'%s');
end
1)This line is for m = 1 to the line of command_output_1
then read the what?
o = 75; %location where coolant density is located in input file
for n = 1:34
Y2(n,1) = str2num(Y1{o, 1}{3,1});
o = o+1;
end
2)This loop str2num is to change str to number, but I don't understand after str2num what is it do?
serpent_command = sprintf('cd RBWR_TB2_2019;printf "%s" "#PBS -l
nodes=n001:ppn=8+n002:ppn=8+n003:ppn=8+n004:ppn=8" "#PBS -V" %s
"/opt/serpent/serpent2/sss2 -omp 32 RBWR_TB2_2019 > screen_output" >
RBWR_TB2_2019.qsub;qsub RBWR_TB2_2019.qsub','%s\n','"cd
$PBS_O_WORKDIR"');
serpent_command = strrep(serpent_command,'"','''');
3) What are these line do? Is it run serpent ?
P.S. I have more code to read,if someone want to give me a contact maybe an email or line it's wil be very grateful.

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 25 Aug 2019
this line mean login to server and find the line with "mat water" and give that line equal to command_output_1, Am I right?
Sounds reasonable -- but ssh2_simple_command is not part of MATLAB, so we do not know what the command does. Perhaps you are using https://www.mathworks.com/matlabcentral/fileexchange/35409-ssh-sftp-scp-for-matlab-v2
then read the what?
textscan() is always going to return a cell array.
With textscan() not having been passed any Delimiter or Whitespace options, and with one line at a time of the response being passed to textscan(), the effect will be that each Y1(m,1) entry will become a cell array of character vectors each of which is one "word" of the output of the line, where "word" is whitespace delimited. There are ways a lot more efficient than textscan() to achieve the same result.
This loop str2num is to change str to number, but I don't understand after str2num what is it do?
Notice the o=75 line. The o=o+1 line of code after the str2num() has the effect of moving on to column 76, 77, and so on, with o ending up as 109, after column 108 was converted. There are a lot more efficient ways of doing this too.
3) What are these line do? Is it run serpent ?
Not exactly. Those lines are preparing a shell command line for later execution, without executing it inside of what you posted so far. The shell command, when executed, would change directories, then create a file of qsub commands, and then invoke qsub to execute the commands, and then cd somewhere else. The shell command being created is to be executed by a Linux shell, it appears to me.

  2 Comments

Thanapong likhitparinya
Thanapong likhitparinya on 12 Sep 2019
o = 75; %location where coolant density is located in input file
for n = 1:34
Y2(n,1) = str2num(Y1{o, 1}{3,1});
o = o+1;
end
So Y1{o ,1} it will convert the data of Y1{o,1} to number and keep it in Y2(n,1) %up to o=109% right? but what {3,1 }do?

Sign in to comment.

More Answers (0)

Tags

No tags entered yet.


Translated by