How to read specific part of the text file?
Afficher commentaires plus anciens
So, I have text file in Notepad data.txt which contain all information about some image for example
- image1.gif
- gif
- 256
- 256
- 155.992455 321.222455 995.452774 741.123478
- 15 24 35
- 41 52 64
- 58 59 50
so I have name of image, extension,height, width, matrix of gray image and matrix of image in this order in file. I made function which receives namefile and parameter which is needed to be read. So I want that the result of function be that parametar from text file for example function:
readformfile('data.txt','MatrixOfImage')
and result should be this
15 24 35
41 52 65
58 59 50
I have written the function but it reads all text from file and I don't know how to read only specific parameter from file
function result=readfromfile(namefile,parameter)
result=fileread(namefile);
end
I would be very grateful if someone could help me.
2 commentaires
dpb
le 13 Déc 2014
I'd probably just build a routine that reads the whole file then sends back the section(s) requested. That way it's all one function to maintain and simply a choice of which data to return. Of course, if you think you're going to be looking at the same file over and over for various pieces, that's a lot of overhead so I'd try to rearrange my higher level usage to avoid that. Memory is cheap these days...so what if you've got some extra stuff hanging around waiting to be used later?
Lolipop
le 13 Déc 2014
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Import and Export dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!