AND operation for different textfiles in MATLAB
2 views (last 30 days)
Show older comments
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 Comments
Image Analyst
on 18 May 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
on 18 May 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.
Accepted Answer
Image Analyst
on 18 May 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 Comments
Image Analyst
on 26 Aug 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.
More Answers (0)
See Also
Categories
Find more on Data Import and Export 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!