필터 지우기
필터 지우기

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 CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by