0

here jj will be the value of FN, but the trouble is iam getting a error message

??? Error using ==> fopen Invalid filename.

DirName  = 'Samples\mattest\jj';
FileName = split('\\',DirName);

[a,b] = size(FileName);
FN = FileName(b);

file_1 = fopen(FN,'w');

split method was found at http://www.mathworks.com/matlabcentral/fileexchange/4873

Doesnt the code seem correct ? Could someone please help me ?

1 Answer 1

1

The 1st argument to FOPEN should be a file name (if the file is locatied in current working directory) or full path to the file.

Why are you splitting the path? Is jj is the name of a file or a directory? You cannot use FOPEN for a directory.

To split a full path to a file to directory name, file name and extension it is better to use MATLAB's FILEPARTS function.

For splitting a string you don't need special split function. Build-in REGEXP can help:

parts = regexp(dirname, '\\', 'split');
Sign up to request clarification or add additional context in comments.

3 Comments

i found the problem , the reason for getting this error is because that the FN string contains two illegal characters '. Does anyone know how to remove them ?
Again try to use REGEXP. It shouldn't give you illegal characters.
How have you discovered illegal characters? Where they come from? Why do you think strrep does not work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.