How to get matlab to open a file based on its file type?

5 visualizaciones (últimos 30 días)
Daniel
Daniel el 12 de En. de 2015
Respondida: Guillaume el 12 de En. de 2015
I've got a large set of data that I am trying to make a matlab file to help navigate. This data contains several different file types like autocad drawings (.ipt), images (.jpeg), PDF files, etc. What I need doing is to have the user click on the file they want opened within the matlab script and then it will open to appropriate program for the user to see.
example: I click on this file name: cadfile.ipt
and it opens AutoCad for me to view that file
Can anyone help set me on this path?
Daniel

Respuestas (2)

Sebastian Castro
Sebastian Castro el 12 de En. de 2015
Hi Daniel,
The easiest thing off the top of my head is the FILEPARTS function, which works like this:
[pathstr,name,ext] = fileparts(filename)
In other words, the path C:\Users\Daniel\cadfile.ipt would return:
pathstr = 'C:\Users\Daniel'
name = 'cadfile'
ext = 'ipt'
Then, you can use the "ext" output if you want to act accordingly on the file based on the extension.
  1 comentario
Sebastian Castro
Sebastian Castro el 12 de En. de 2015
Actually, let me back up a little because there's other functions that maybe do exactly what you want.
UIOPEN: Opens up a window (based on your operating system) where users can then select files. Whatever default program you set up outside MATLAB will be what's used to open the file. If you know the name/path of the file already, you can just enter the file name as an argument, bypassing the user selection dialog.
UIGETFILE: Opens up the same window as UIOPEN, but instead of opening file after the user selects it, it simply returns the name and path of that file. So, if you want your code to be more "intelligent" about opening files, you can use this and then have some logic based on the extension, etc.

Iniciar sesión para comentar.


Guillaume
Guillaume el 12 de En. de 2015
On windows, use winopen:
winopen('cadfile.ipt');

Categorías

Más información sobre Debugging and Analysis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by