writematrix is not creating a new .csv file for writing matrix to if it does not already exist.
24 views (last 30 days)
Show older comments
Info sheet for writematrix function says that it will create a new file with the 'full filename path' if it does not already exits. This is not happening and I am getting a 'Cannot find 'full filename path' instead.
1 Comment
Walter Roberson
on 22 May 2022
Edited: Walter Roberson
on 22 May 2022
Are you possibly using the "WriteMode", "append" option?
If you are passing in a path with directory, does the directory already exist? The function will not create directories.
Answers (3)
Image Analyst
on 22 May 2022
Show the code where you're creating the folder name and the full file name. You seem to have forgotten to upload it. It should look something like
folder = 'c:\whatever'
if ~isfolder(folder)
% Create folder if it doesn't exist. Maybe writematrix does this for you
% -- I'm not sure because you're saying it doesn't, so I'm doing it manually here.
mkdir(folder)
end
baseFileName = 'My Data.csv';
fullFilename = fullfile(folder, baseFileName);
if isfile(fullFileName)
% Delete any existing file with the same name.
delete(fullFileName);
end
writeMatrix(myData, fullFileName);
Waiting for your reply, after you read this link of course:
2 Comments
Amina Alihodzic
on 23 May 2022
@Image Analyst is it possible to get yout e-mail :) I have a few questions for you regarding steganography..
Image Analyst
on 23 May 2022
Sorry, no. Ask them in Answers where everyone can benefit from the topic. I am not an expert in steganography so I'll probably just say "I don't know" to whatever you ask. I'm attaching a few demos.
GJohnson2
on 23 May 2022
Edited: Walter Roberson
on 23 May 2022
1 Comment
Walter Roberson
on 23 May 2022
Which operating system are you using that has "Documents" directly under the root directory ?
"Documents" is much more likely to be under the user's home directory, such as /Users/GJ2/Documents/Matlab/data/ and so on.
I do not see anywhere in your code where you are creating any directory Documents/Matlab/data/S%d/Exp%d that does not already exist.
Image Analyst
on 23 May 2022
If you're doing something like
date_str = datestr(now)
that won't work because it has colons in the string and you can't have colons in the filename anywhere except in the second position to separate the drive letter from the folder. To fix, get rid of the colons:
rfile_1 = strrep(rfile_1, ':', '') % Get rid of colons.
0 Comments
See Also
Categories
Find more on Data Import and Export in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!