AND operation for different textfiles in MATLAB

1 回表示 (過去 30 日間)
Chethan
Chethan 2013 年 5 月 18 日
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
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
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
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 件のコメント
Chethan
Chethan 2013 年 8 月 26 日
Well thank you, Now allMatchingStrings contains
'DSC01605.bmp'
'Hampi8.bmp'
How can i write these files to a new text file all.txt? Problem with my requirements is - suppose allMatchingStrings contains around 10 files, but i need only 5 out of those 10 files. I need to save 5 files to a new text file say all.txt. How can i do that?
Image Analyst
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 ExchangeData Import and Export についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by