Error message while using Fullfile to write .m file in a specific folder
조회 수: 5 (최근 30일)
이전 댓글 표시
Hello,
I have some troubles using fullfile function in order to store outputs in a specific folder.
Error using fullfile (line 61) An unknown error occurred in FULLFILE while constructing the file specification.
Error in Test_Export (line 14) f=fullfile(myFolder,fileID);
Caused by: Error using horzcat The following error occurred converting from logical to char: Error using char Conversion to char from logical is not possible.
The code i'm using is attached. Any ideas please to fix it?
Thank you in advance for your help
Fatzo
댓글 수: 0
채택된 답변
Guillaume
2015년 4월 28일
There are two problems with your code:
myFolder=mkdir('C:\Users\fatima.smime\Documents\MATLAB\Pro...')
myFolder is not the name of the folder you've created, it's just the status code telling you whether or not the folder creation was succesful. This is possibly what you meant:
myfolder = fullfile('C:\Users\fatima.smime\Documents\MATLAB\Programmes These FZS\Plaque\Modele direct plaque\Avril 2015\Simulations_MD', filename);
mkdir(myfolder);
Secondly, as pointed out by pfb,
f = fullfile(myFolder, 'fileID');
should be
f = fullfile(myFolder, fileID);
While the above two should stop the error from happening, your code is very confusing. Is filename the name of a file or a folder? It sounds like the name of a file, yet you use it to create a folder. Secondly, why do you have \n in some of your num2str conversion. Thankfully they're ignored as that would cause problem later in your code.
Finally, I find sprintf much easier to read than num2str + string concatenation. It's also more efficient:
filename= sprintf('pas%dfreq%gFech%gNtot%d', pas, f0, 1/Tech, Ntot1);
댓글 수: 8
Guillaume
2015년 4월 29일
It should have been obvious that fullile was a typo and that it should have read fullfile. This is after all the title of your question.
I've now fixed the typo.
99% of the errors of the type undefined function xxx for input argument of type yyy are due to the function xxx not being found either because it is mispelt or because it's not on the path. It's rarely to do with the arguments.
추가 답변 (1개)
pfb
2015년 4월 28일
I think it might have to do with this: in your code you define the name of the file in a char variable
fileID=['tilt',num2str(tiltd,'%-f'),'prof',num2str(depth_d),'.m'];
which looks something like 'tiltFFFFfprofDDDD.m'
but then, when you call fullfile, you do not use that char variable (fileID), but 'fileID'
f=fullfile(myFolder,'fileID');
I think you meant
f=fullfile(myFolder,fileID);
댓글 수: 2
pfb
2015년 4월 28일
ok... can you post a mat file containing the variables "myFolder" and "fileID" you feed to fullfile?
The path in your code is for a Windows system. Apologies for the silly question, but are you running your code on a Windows machine?
Finally, formatting the code bits in your posts would make them more readable.
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!