I am iterating through a directory and storing the full path of a file and its label in a cell matrix in Matlab this way:
image_directory=dir(['path_for_directory/' char(folder1) '/' char(folder2)]);
for j=3:size(image_directory,1)
myCellArray{index_image}{1}=['path_for_directory/' char(folder1) '/' char(folder2) '/' image_directory(j).name];
myCellArray{index_image}{2}=label;
index_image=index_image+1;
end
end
end4
After I finish filling this cell matrix I want to save its contents (strings and integers) in a text file. I did something like the suggestion in (http://www.mathworks.com/matlabcentral/answers/112695-how-to-write-an-array-containing-letters-and-number-to-file). Here Is what I tried:
fid = fopen('data_out.txt','w');
for i=1:size(myCellArray,1)
fprintf(fid, '%s \t %s\n', myCellArray{i,1}, sprintf('%d ', myCellArray{i,2}));
end
fclose(fid);
The problem is, when I execute this source code in matlab I have the following error:
Error using sprintf
Function is not defined for 'cell' inputs.
Error in write_files (line 50)
fprintf(fid, '%s \t %s\n', myCellArray{i,1}, sprintf('%d', myCellArray{i,2}));
What Is wrong with my code?
myCellArray{i,2}
a number? – SamuelNLP