이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
How do you read .dat file that contains 5 .jpg images in it using textread?
Also, how do you output the filenames?
채택된 답변
Walter Roberson
2012년 6월 22일
0 개 추천
jpg images are binary images, but textread() is for reading text files.
Does the .dat file perhaps contain the names of the images rather than the images themselves?
There is no standard format for .dat files: it is a suffix used by any program to hold any data. You need to know the internal structure of that particular .dat file in order to work with it. It might be pure text (most .dat files are not).
If you can upload a sample of the file, someone might have a look at it. http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
댓글 수: 9
Jonathan
2012년 6월 22일
Yes, it is 5 strings of the names of the images. Not the images themselves.
Jonathan
2012년 6월 22일
Would using fscanf be better? I want it to print out the names of the images.
Jonathan
2012년 6월 22일
What about fgets?
Also, I would like to write the "printout" of the names of the images to a .txt file. How do I do that?
Walter Roberson
2012년 6월 22일
A lot depends on the file format.
You could probably use fileread(), together with regexp() with the 'split' option.
Jonathan
2012년 6월 23일
Thanks so much for telling me about fileread! It's a life saver. Anyways, I now have my 5 strings stored in a variable called filename. How to a write the contents of filename to a new txt file?
Jonathan
2012년 6월 23일
I mean not write to a txt file, I mean create a new .txt file with filename in it
Jonathan
2012년 6월 23일
Ok, so I figured out how to make a txt file by using fprintf, but it doesn't seperate the strings that are in filename with line breaks. How do I make it do that?
Walter Roberson
2012년 6월 23일
I'm not sure what you mean, but anyhow...
fid = fopen('TheFileName.txt','wt');
fprintf(fid, '%s\n', filename{:});
fclose(fid)
I am assuming here that filename is a cell array of strings. If it is a plain string then you may have to break it apart if you want one filename per line. Or perhaps just
fid = fopen('TheFileName.txt','wt');
fprintf(fid, '%s\n', filename);
fclose(fid)
Jonathan
2012년 7월 5일
Thanks a lot! I just needed to add the t next to the w in 'wt' in fid = fopen('TheFileName.txt','wt');. It works perfectly now.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
