How do I direct the publish html output to the user given directory in which the resulting workspace is saved at the end of the script?

5 次查看(过去 30 天)
I want to write the publish output (html) into the corresponding directory folder of the processed measurement into which the workspace is saved as well. The default folder name "html" should become something like "html data 2017-04-28_1_191221" where '_1_' enumerates the current run of measurement '191221'. This way getting the following structure:
  • Specimen 1
  • measurement 191221
  1. Workspace_<date>_1_191221 √ this works already
  2. Workspace_<date>_2_191221 √ this works already
  3. html_<date>_1_191221 - to be solved
  4. html_<date>_2_191221 - to be solved
  • measurement yyyyyy...
  • Specimen 2...

采纳的回答

Manfred
Manfred 2017-8-22
Many thanks to all who thought about a solution!
With the following manual workaround I realised the transfer of the Publish HTML output to the target location. After having run the main script I trigger a "post processing" for the Publish Output and run the following script file:
%%Move the Publish output in the specimen MATLAB result folder
% stack = dbstack;
% isBeingPublished = ismember('publish', {stack.name}); % this variable is set in main script
if isBeingPublished
myScriptFile = mfilename('fullpath'); % location of script file
[BaseDir,~,~] = fileparts(myScriptFile);
fname = fullfile(BaseDir,'html');
if exist (fname,'dir') == 7 % if the directory still exists
fnameNew = fullfile(strcat(fileparts(path),'/',newDir,'/html_',num2str(counter),dataFilePart)); % specified path and new folder name
movefile(fname,fnameNew); % move to target location
msgbox({'Published HTML output successfully' 'moved to target location'},'Info')
else
if exist(fnameNew,'dir') == 7 % Another run of this script doesn't harm
msgbox({'Published HTML output already' 'moved to target location'},'Info')
else
msgbox({'No result folder found!' '-- Something really went wrong!'}, 'Attention', 'error') % last exit - think ... :-)
end
end
end
If someone can trigger this script from the main script - please let me know how to manage this.

更多回答(1 个)

Kristen Amaddio
Kristen Amaddio 2017-7-27
You can specify an output directory for the HTML files using the 'outputDir' property:
You can either specify this in the 'options' for the 'publish' function, or within the call to 'publish' itself.
For example, in order to publish the file in the directory 'html_<date>_1_191221' for run 1 of measurement 191221, you would do the following:
% These can be defined within the loops you are using
run = 1; measurement = 191221;
% Specify the desired output directory, then publish the file
outDir = strcat('html_',datestr(now,'yyyy-mm-dd'),'_',num2str(run),'_',num2str(measurement));
publish('myFile.m','outputDir',outDir)
  2 个评论
Manfred
Manfred 2017-7-30
Thanks for this answer, however, it doesn't solve my intended solution. With the use of the user supplied function p_input I go through a lengthy dialog in which the desired functions are triggered to show different aspects of the measurement data. In the end I make use of the following construct to save the results:
*Create a New Unique Named Directory*
cd (strcat(pathBase,'/',specimen,'/')); % pathBase is short for the source of all measurements
dataFilePart = num2str(path(end-6:end)); % the last part of the data directory used for evaluation
counter = 1;
newDir = horzcat('matlab data ', datestr(now,'yyyy-mm-dd'), '_',...
num2str(counter), dataFilePart);
while (exist (newDir, 'dir')) == 7. % if the directory exists - create a new one
counter = counter + 1 ;
newDir = horzcat('matlab data ', datestr(now,'yyyy-mm-dd'), '_', ...
num2str(counter), dataFilePart); % concatenate a new directory name
end
mkdir(newDir); %create directory with processing date of data
cd (newDir);
With the function p_input (short for "publish_input" thanks for this!) the publish button can be used and my various results are documented/stored in the directory newDir, however, the html output generated by publish is always written with the generic name html into the script directory and not to the directory newDir with the newly generated name html_date_n_measurement.
Is it possible to automatically trigger a second script (when the html output directory is written) that uses the current workspace paths and accordingly renames the default publish output and moves it to the directory newDir?
Many thanks in advance
Baptiste Ottino
Baptiste Ottino 2017-8-3
I don't think that is necessary. Is there any particular reason you want to use the publish button and not the function directly? If you used the function, Kristen's solution would probably work.
You can also try the "Edit Publishing Options" button (the down-facing arrow under "Publish"). It allows you to specify the output directory for the html file, but only for the current script if I am not mistaken.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by