|
From: saneman on 4 May 2008 09:51 I would like to store the number of files in the current dir in a variable. In a unix shell this can be done with: ls -l | awk '!/^d/{print }' | wc -l or ls -1 | wc -l But matlab will only accept the second command. If I try the first I get: a = unix(ls -l | awk '!/^d/{print }' | wc -l) ??? Error: File: test.m Line: 4 Column: 22 Unexpected MATLAB expression. I have also tried to insert quotes: a = unix('ls -l | awk '!/^d/{print }' | wc -l') But it gives the same error. How do I run the above commmand?
From: Bruno Luong on 4 May 2008 13:54 unix command requires a string as input Strings in MATLAB are braketed by quote "'". If you want to insert a quote inside a string, then put two consecutive quotes (this is MATLAB convension). cmdstring = 'ls -l | awk ''!/^d/{print }'' | wc -l'; [status result] = unix(cmdstring) Alternatively you could use MATLAB command dir. Bruno
From: Walter Roberson on 4 May 2008 13:58 In article <481dbf56$0$90273$14726298(a)news.sunsite.dk>, saneman <ddd(a)sdf.com> wrote: >a = unix('ls -l | awk '!/^d/{print }' | wc -l') The second ' ends the string. You need a = unix('ls -l | awk ''!/^d/{print}'' | wc -l') On the other hand, Matlab arrives with perl installed, so you can run the whole thing in perl instead. > I would like to store the number of files in the current dir in a > variable. fids = dir; a = sum(~[fids.isdir]); -- Q: Why did the chicken cross the Mobius strip? A: There were manifold reasons.
|
Pages: 1 Prev: A complex mesh grid boundary for plotting Next: image analysis question |