AND operation for different textfiles in MATLAB
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sorry, i could not able to edit/comment on my previous qquestion AND operation for textfiles in MATLAB
I've 3 .txt files. I want to perform and operation to these 3 text files and to save the output in a new text file.
fid = fopen(AND('a.txt','b.txt','c.txt'));
I don't know this is correct or not, will this work as per my requirements? but i want to save in a new text file, how can i go for it?
For example my a.txt file contents are
DSC01605.bmp
Hampi8.bmp
DSC01633.bmp
DSC01198.bmp
DSC01619.bmp
similarly some images are present in b.txt file, and hence in c.txt file. I just want to get similar image names out of those files which are saved in above text files, and want to save in a separate new text file.
2 commentaires
Image Analyst
le 18 Mai 2013
Why were you not able to edit your original question? What happened when you clicked the edit link? Please tell files@mathworks.com so they can fix it.
Jan
le 18 Mai 2013
@Chetan: Posting multiple messages about the same problem is not efficient in a forum, because it wastes the time of the readers.
AND() is a logical operation. Applying it to the file names is a very strange idea, because you want to process the file contents.
Réponse acceptée
Image Analyst
le 18 Mai 2013
Use ismember():
first read the files into cell arrays. Then:
file1 = {'DSC01605.bmp';'Hampi8.bmp';'DSC01633.bmp';...
'DSC01198.bmp';'DSC01619.bmp'}
file2 = {'DSC01605.bmp';'Hampi8.bmp';'DSC01633.bmp'}
file3 = {'DSC01605.bmp';'Hampi8.bmp'}
matching12 = ismember(file1, file2)
matching13 = ismember(file1, file3)
matchesAll3 = matching12 & matching13
allMatchingStrings = file1(matchesAll3)
2 commentaires
Image Analyst
le 26 Août 2013
Use fopen(), fprintf(), and fclose() to write strings to a text file. You will have to decide which of the strings to save. I have no idea, and MATLAB will know only after you tell it.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Import and Export dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!