How to write a circulation when save selected data into new matrix and then save new matrix into a text file
Show older comments
I have a 140*1 matrix 'res' which consists of integers from 1 to 5.Now I am going to save all row numbers of integer into a new matrix label 1, and all row numbers of integer into a new matrix label 2. I used code below to get the corresponding data. However, if i don't know the length of original matrix 'res', how can i get the data using a circulation.(e.g label 'p'=find(res==p))
nClass = length(unique(res));
label1=find(res==1);
label2=find(res==2);
label3=find(res==3);
label4=find(res==4);
label5=find(res==5);
fid=fopen('1235.txt','wt');
fprintf(fid,'Docum ID: ');
fprintf(fid,'[%d] ',label1);
fprintf(fid,'\n\n');
fprintf(fid,'Docum ID: ');
fprintf(fid,'[%d] ',label2);
fprintf(fid,'\n\n');
fprintf(fid,'Docum ID: ');
fprintf(fid,'[%d] ',label3);
fprintf(fid,'\n\n');
fprintf(fid,'Docum ID: ');
fprintf(fid,'[%d] ',label4);
fprintf(fid,'\n\n');
fprintf(fid,'Docum ID: ');
fprintf(fid,'[%d] ',label5);
fprintf(fid,'\n\n');
fclose(fid);
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!