現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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 日
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 で Convert Image Type についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
