On Code Ocean, files need to be saved to
/results to be visible as results.
When you export a capsule, it will come with a
/results folder inside the exported folder. Some users may not want a new folder created for them, for example they are downloading the code and data separately rather than exporting the capsule as a whole -- and their local workflow may be to just wait for figures to pop up in their IDE or terminal.
For these use cases, you can use either shell scripting or MATLAB syntax.
if [ -d "$DIRECTORY" ]; then
# run your code
# save your figure
After generating your figure, you'd run something like
if ~usejava('desktop') saveas(gcf,'../results/figure1.pdf') end
If you have other languages you'd like to see syntax for, plese communicate this via live chat or an email to email@example.com, and we'll amend this article accordingly.