mkdir and the matlab compiler

Hi, I'm having a problem getting the compiled version of my code to make a new directory - I use mkdir and it works great in the m-file, but I get nothing out of the compiled version. I found on thread suggested adding this statement in files related, but it doesn't seem to do anything and I likely don't understand how to use it.
*%#function mkdir *
The code compiles and creates the excel datafile, but not the directory or creates the file in the directory..
Here is a snippet of my code -
measurementTitle = 'Test-title';
good_iteration_name = sprintf(char(cat(2,measurementTitle,char(datestr(now,30)))));
%
% Create a new directory to store the data into and at the end cd back to "root". "Ant_serial_num2" is the "measurement title" in the GUI.
dataDir = sprintf(char(good_iteration_name));
%
comments = [comments,' ', num2str(operatingFreq) 'Hz']
%
mkdir(dataDir)
% eval(['mkdir ' dataDir])
cd(dataDir)
%eval(['cd ' dataDir])
%
characterizationVoltages = [voltageSet' chan1' chan2'];
characterizationVoltages = num2cell(characterizationVoltages);
%
dataVoltages = sprintf(char(cat(2,good_iteration_name,'_charVoltages','.xlsx')));
saveAsFN = dataVoltages; %
%format for xlswrite2- Data, tab name, column names, filename.
%
headerTemp = sprintf('Voltage %s', voltageSetTo);
colNames = {'DAQ Voltage Setting','VPP-Current', 'VPP-DrvOut',comments};
%
% subjectTemperatures also contains oscope voltages.
xlswrite2(characterizationVoltages, headerTemp, colNames,dataVoltages);
pause(2)
%
cd ..

3 comentarios

Mike
Mike el 6 de Mzo. de 2012
You cannot use the %#function pragma to refer to functions that are not available in MATLAB code.... ok, so mkdir is out I guess.
I'm using win7, 2011b, 64bit.
Friedrich
Friedrich el 6 de Mzo. de 2012
Hi,
why are you using eval?
eval(['mkdir ' dataDir])
You can use the function syntax of mkdir
mkdir(datadir)
In addition you use CD, dont do that. It will most likely result in same strange errors:
http://blogs.mathworks.com/loren/2008/08/11/path-management-in-deployed-applications/
Mike
Mike el 6 de Mzo. de 2012
Hi Friedrich,
I have used both, I tried eval(['mkdir ' dataDir]) to see if the compiler would handle it better. Actually cd works fine with the compiler-compiled version. The cd.. drops me from the compiled directory to the one below it. It would probably cd me into the new directory also if I could create the new directory.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 6 de Mzo. de 2012

0 votos

The first thing I would suspect is that the problem is that you have no idea what directory you are starting in at the time you try to 'mkdir' . You cannot just mkdir() starting from a random place.
The link Friedrich provided should help clarify matters.

5 comentarios

Mike
Mike el 6 de Mzo. de 2012
Hi Walter,
I'll have to think about it, but the m-code using these lines works great. Maybe the compiler isn't happy without a known directory? The cd.. does seem to drop me from the compiled directory as expected. I've read through a few postings of other people having problems with mkdir when compiled, but I haven't seen any answers.
I guess this is considered a shell command and maybe I need to search from that set of terms?
Mike
Mike el 6 de Mzo. de 2012
It has been creating them in an obscure cache directory under user\appdata\.. etc. It interestingly creates the excel file too there and it creates and identical file under documents.... I have to figure out how to path from the origination directory.
Mike
Mike el 7 de Mzo. de 2012
another key is the environment variable, set CTF_CACHE_ROOT=c:temp (no spaces around the '=')or where ever instead of the default obscure location. That is where my files and folder were created.
Image Analyst
Image Analyst el 7 de Mzo. de 2012
Put this line in your code
ctfroot
and see what it spits out to the console window. Chances are Windows 7 is not allowing your program to make a folder in that folder. Even in folders under c:\Users, you can't always put files and folder just any old place - there are rules. You'd probably be better off specifying where you want files and folder created explicitly rather than using relative paths which could be who-knows-where.
Mike
Mike el 7 de Mzo. de 2012
Good points. It was actually creating them, I just didn't know where and it was confusing because it seemed to create 2 data files, one in the new directory created in the user\temp\oscure named location, but another in \documents.

Iniciar sesión para comentar.

Categorías

Más información sobre Scripts en Centro de ayuda y File Exchange.

Preguntada:

el 6 de Mzo. de 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by