writematrix is not creating a new .csv file for writing matrix to if it does not already exist.

23 visualizzazioni (ultimi 30 giorni)
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 Commento
Walter Roberson
Walter Roberson il 22 Mag 2022
Modificato: Walter Roberson il 22 Mag 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.

Accedi per commentare.

Risposte (3)

Image Analyst
Image Analyst il 22 Mag 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 Commenti
Image Analyst
Image Analyst il 23 Mag 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.

Accedi per commentare.


GJohnson2
GJohnson2 il 23 Mag 2022
Modificato: Walter Roberson il 23 Mag 2022
It looks like the writematrix function is not completed successfully, and throws a catch error.
The code is:
rfile_1 = sprintf('/Documents/Matlab/data/S%d/Exp%d/S%d_Exp%d_RIGHT_%s.csv', snum, exp_num, snum, exp_num, date_str);
try
writematrix(SubDataVals, rfile_1);
catch
fprintf('Cannot find %s\n',rfile_1);
end
  1 Commento
Walter Roberson
Walter Roberson il 23 Mag 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.

Accedi per commentare.


Image Analyst
Image Analyst il 23 Mag 2022
If you're doing something like
date_str = datestr(now)
date_str = '23-May-2022 12:49:11'
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.

Categorie

Scopri di più su Data Import and Export in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by