I have created folders using an array 1-6 and loaded the CSV file now I want to save data from CSV file to the folder in form of text file.. kindly help me
Mostrar comentarios más antiguos
for k=0:6
[status, msg, msgID] = mkdir(num2str(k));
end
X = importdata('data.csv');
*the CSV file has the folowing data*
file values
0 1 2 3 4 5 6 7 8 9 10
2 11 12 13 14 15 16 17 18 19 206
1 21 22 23 24 25 26 27 28 29 30
first column = file in which 0, 2 ,1 are names of folders second column = values which contains few numbers i want to save theses numbers in form of text file into respective folders.
how to do this .. kindly help me
Respuesta aceptada
Más respuestas (1)
Here's an example with some dummy data.
dummydata = {0, 1:9;1,11:19;2,21:29;}
for k=1:size(dummydata,1)
mkdir(num2str(dummydata{k,1}));
filename = fullfile(pwd,'/',num2str(dummydata{k,1}),['dummy_' num2str(dummydata{k,1}) '.csv']);
dlmwrite(filename,dummydata{k,2});
end
10 comentarios
saeeda saher
el 2 de Nov. de 2017
data = csvread('data.csv');
and if your data is an array with three rows just like your example (only the values part), then you could replace dummydata{k,2} from the above example with data(k,:)
saeeda saher
el 4 de Nov. de 2017
KL
el 4 de Nov. de 2017
It was an example, you could have modified the folder and file names however you want!
Anyway, now I have made the changes you want to save it under folder names "0,1, and 2" and the filenames would be "dummy_" and the foldername. If you don't want the dummy prefix, remove it on the 4th line of the code.
and remember, the dummydata cell array is also with some example data, you have to modify it's contents, first column should be your folder names, second column should be values.
saeeda saher
el 4 de Nov. de 2017
KL
el 5 de Nov. de 2017
Please attach a sample of your file
KL
el 5 de Nov. de 2017
That's not sample data! that's a screenshot of the data you have! Please attach the file using the paperclip icon.
saeeda saher
el 5 de Nov. de 2017
Editada: saeeda saher
el 5 de Nov. de 2017
Stephen23
el 5 de Nov. de 2017
That is not a CSV file. Just because you gave something the file extension .csv does not magically make it into a CSV file. It is not a CSV file, and it is not even a text file! Here is a screenshot of it, opened in Notepad++:

Does that look like a CSV file to you? Does that look like your data? Here is the that I get when I unzipped it:

That is the inside of a .xlsx file, or something similar. As requested please upload an actual CSV text file.
saeeda saher
el 5 de Nov. de 2017
Categorías
Más información sobre Text Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!