Error using fprintf. Function is not defined for 'struct' inputs.
Show older comments
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!
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with MATLAB 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!