Convert script using system commands from Linux to Windows
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Elise
il 11 Feb 2023
Risposto: Walter Roberson
il 11 Feb 2023
Aiming to use this code on a Windows computer (it works with no issues on MATLAB online but want to run it on the desktop version). ivtfile is a netcdf files. Getting errors saying 'ls is not a recognised internal or external command'. I have tried replacing 'ls' with 'dir' but it does not give me the correct output.
[~,cmdout]=system(['ls -1 ',ivtfile]);
ivtfiles=textscan(cmdout,'%s','delimiter','\n');
ivtfiles=ivtfiles{1};
nfile=numel(ivtfiles);
[outdir,~,~]=fileparts(outfile);
0 Commenti
Risposta accettata
Walter Roberson
il 11 Feb 2023
Unless ivtfile has wildcard patterns recognized by your linux shell, use
dinfo = dir(ivtfile);
outdirs = {dinfo.folder};
ivtfilenames = fullfile(outdirs, {dinfo.name});
nfile = length(filenames)
ivtfilenames will be the fully-qualified file names. outdirs will be a cell array of folder names. You would typically only create a separate array to hold all of them if you had the case that the input ivtfile was a pattern that matched several directories, such as
ivtfile = 'ivt*/*.xlsx';
intending to match xlsx files in multiple folders each of which begins with "ivt"
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su File Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!