LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   batching over an input list (https://www.linuxquestions.org/questions/linux-newbie-8/batching-over-an-input-list-4175432347/)

atjurhs 10-15-2012 02:55 PM

batching over an input list
 
Hi guys,

hope you guys can help....

I have a MatLab code that I'll call "MatLab_Processing_Tool" that takes the path and filename from a file that list them out. I'll call that text file "ListFile". Right now in ListFile I have to comment out and in the filenames and paths (one at a time) to get the MatLab_Processing_Tool to run, but the problem I have is like 100 or more of these text files need to be run by passing them into it the path and filename and assigned by fnarr. I know how to create the ListFile, but can I somehow batch assigning them to fnarr?

"ListFile"
Code:


fnarr = '/home/tabitha/many_files/file_typeA_1.txt';
%fnarr = '/home/tabitha/many_files/file_typeA_2.txt';
%fnarr = '/home/tabitha/many_files/file_typeA_3.txt';
%fnarr = '/home/tabitha/many_files/file_typeB_1.txt';
%fnarr = '/home/tabitha/many_files/file_typeB_2.txt';
%fnarr = '/home/tabitha/many_files/file_typeB_3.txt';
%fnarr = '/home/tabitha/many_files/file_typeC_1.txt';
%fnarr = '/home/tabitha/many_files/file_typeC_2.txt';
%fnarr = '/home/tabitha/many_files/file_typeC_3.txt';

etc....

MatLab_Processing_Tool( fnarr );

call me lazy but, I just don't want to have to pass into fnarr paths and file names 100 or more times :)

thanks so much, Tabitha

alinas 10-15-2012 04:53 PM

I can't answer your question, because I don't know Matlab language. But that's my point. I think you are more likely to get an answer from a more specific forum, such as http://www.mathworks.co.uk/matlabcentral.

atjurhs 10-15-2012 10:22 PM

I don't think, but I could be wrong, that this is not a MatLab question at all. The only thing that MatLab cares about is what path and file is assigned to fnarr. So I jsut need a script that feeds MatLab a new fnarr every time it makes a call for one. Also I'm pretty sure that MatLab will take standard shell commands, maybe even awk

Kenarkies 10-15-2012 10:44 PM

Yes we may be able to help but we need more clarification. Am I right in understanding that you have a file with a list of filenames, and you want to feed them one at a time to another program (MatLab_Processing_Tool in this case). By the look of it you are commenting out all but one file (using % as a comment directive) and feeding the resultant file to Matlab. The last line - is that a part of the file or is it a script run inside Matlab. Are you wanting to run this "MatLab_Processing_Tool" on each filename at a time? If so, wouldn't that need a Matlab script? I confess to being a bit lost.

Is there a way to invoke MatLab_Processing_Tool outside of Matlab just using the desired filename? (e.g. matlab -f filename.txt or something) so that you can build a script to extract one filename from the listfile at a time and feed it to Matlab. That shouldn't be too hard to do in bash. Otherwise there are tools to either comment out or delete unwanted names.

shivaa 10-15-2012 11:02 PM

As far as I unuderstood, you want to pass all files one by one to MatLab_Processing_Tool( fnarr ).... Right?
Well, this could be achieved by using a simple shell script.
First, get a list of all files that you want to pass into the fnarr, as follow:
ls -la | awk -F" " '{print $8}' > /tmp/ListFiles.txt
Then create a simple script as:
#!/bin/sh
LIST="/tmp/ListFiles.txt"
for file in `cat $LIST`
do
MatLab_Processing_Tool( fnarr )
done


Make this script executable using chmod +x scriptname.sh and invoke using ./scriptname.sh
So try it out, and let's know if you still have any issue.

padeen 10-16-2012 05:27 AM

If I understand you, you want to pass the ListFile line-by-line to M_P_T? Create this file runMPT

Code:

#!/bin/sh

cat ListFile | { while read LINE ; do
    Matlab_Processing_Tool($LINE)
    done
}

Make it executable chmod +x runMPT and you should be good to go.

@meninvenus: how do you write inline code with mono font, as per your chmod example?

atjurhs 10-16-2012 02:52 PM

I got this one solved by a little while loop

shivaa 10-17-2012 12:06 AM

Quote:

Originally Posted by padeen (Post 4806972)
@meninvenus: how do you write inline code with mono font, as per your chmod example?

In advanced reply mode (not in quick reply), select the text you want to change font type, and then under fonts option, select courier or Fixedsys font. It will work. :-)


All times are GMT -5. The time now is 05:11 AM.