How to adapt matlab with a new file format?

1 visualizzazione (ultimi 30 giorni)
JMS
JMS il 17 Ott 2014
Risposto: John D'Errico il 17 Ott 2014
Hi all,
If I need to add a new file extension such as *.abcd which is not supported by matlab, where I have to start?
Many thanks

Risposte (3)

Orion
Orion il 17 Ott 2014
Hi,
What do you want to write in this file ? Text, formatted binary file ,...
for a text, you can do the usual operation using fopen, fprintf, fclose.
fid = fopen('TestFile.abcd','wt');
fprintf(fid,'Hello World\n');
fclose(fid);
and then to read this file, just use textread
Text = textread('TestFile.abcd','%s','delimiter','\n')
  1 Commento
JMS
JMS il 17 Ott 2014
Hi Orion,
No it is kind of images which is not supported by matlab. If I want to open it in matlab, it needs to be saved as *.tif format and then I can open it.
Many thanks.

Accedi per commentare.


Orion
Orion il 17 Ott 2014
I'm no expert in image processing, but can't you just use imread ?
if you're really stuck, you should add an example attached to your question, because it's hard to guess what can happen with your special extension, or contact Mathworks.

John D'Errico
John D'Errico il 17 Ott 2014
If this is a file type that is NOT supported by MATLAB for reading, then nothing you do will make imread (or whatever file read tool you want) read it. Code needs to know what to expect. No magic exists.
Having said that, there is no reason why you cannot read in this file, however you will need to write code that knows how to read the file. MATLAB can see the file in your directories, regardless of what the extension is. So you will need to write a tool that understands what the file is. Are there headers? If so, then read them in, in the appropriate format, since YOU know what to expect. You might be using tools like fopen, fclose, fgets, fgetl, or perhaps textread.

Community Treasure Hunt

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

Start Hunting!

Translated by