Error using fprintf. Function is not defined for 'struct' inputs.
Mostrar comentarios más antiguos
I'm reading all the DICOM files in a directory. I'm supposed to run 1 file after the other for K-NN classification. So, I run a loop, and individually classify the files for which I've used the for loop.
dicomFiles = dir('*.dcm');
for k = 1:(numfiles)
I=dicomread(strcat(location, '\', dicomFiles(k).name));
This is where I've called knnclassify() and when I use disp(xclass), it results in either of the groups i.e, 'Yes' or 'No'.
xclass = knnclassify(SM, B, G, VK, METH, RULE, KF);
I'm supposed to write the result of the classification into a file with the format -
Name Group
C1.dcm Yes
N1.dcm No
So, I've used the following code to write the contents into a file.
%Output KNN results to a file
op_dir = 'F:\8th sem Project\Code\KNN Result';
if exist(strcat(op_dir,'\KNN_Result.dat'),'file')
delete(strcat(op_dir,'\KNN_Result.dat'));
end
op = strcat(op_dir,'\KNN_Result.dat');
fid3 = fopen(op, 'a+');
fprintf(fid3, '%s %s \n', dicomFiles(k), xclass);
However, I get an error saying - Error using fprintf. Function is not defined for 'struct' inputs. I've tried going through all the posts on the internet regarding the same, but if I change it to dicomFiles{k}, there are different errors. I'm not used to with the syntax of Matlab. Please help!
5 comentarios
Greg
el 22 de Mzo. de 2017
Your answer is on line 3 of the first block of your own supplied code.
Stephen23
el 22 de Mzo. de 2017
dicomFiles(k).name
As Greg told you, this already is used on line three.
prahlad h
el 22 de Mzo. de 2017
Walter Roberson
el 28 de Dic. de 2017
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Get Started with MATLAB 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!