显示 更早的评论
How do you read .dat file that contains 5 .jpg images in it using textread?
Also, how do you output the filenames?
采纳的回答
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 个评论
Yes, it is 5 strings of the names of the images. Not the images themselves.
Would using fscanf be better? I want it to print out the names of the images.
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?
A lot depends on the file format.
You could probably use fileread(), together with regexp() with the 'split' option.
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?
I mean not write to a txt file, I mean create a new .txt file with filename in it
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?
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)
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!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 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)
