AND operation for different textfiles in MATLAB
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Image Analyst
2013-5-18
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
2013-5-18
@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.
采纳的回答
Image Analyst
2013-5-18
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 个评论
Image Analyst
2013-8-26
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!