필터 지우기
필터 지우기

How can I call inside a function a file *.* ?

조회 수: 2 (최근 30일)
Paschalis Garouniatis
Paschalis Garouniatis 2017년 11월 3일
댓글: Walter Roberson 2017년 11월 3일
I have a set of files with the same name and different extensions, let them be a.env, a.shd, a.arr . I have created a script which calls those files inside a function. Is it possible to set those files as variables so that i can use them whenever it is necessary? I have already used the function genvarname but only for the 'a'. I don't know what to do with the extensions. Can anyone help? Thanks in advance.
  댓글 수: 1
Paschalis Garouniatis
Paschalis Garouniatis 2017년 11월 3일
I used the fileparts and uigetfile functions to store the filename as a variable and they worked. However when i call them inside a function i get error. For example :
%1st case
file='/home/raptor/Desktop/BELLHOP_LAB/Bellhop_results/Ray_trace/a.ray';
[filepath,name,ext]=fileparts(file);
plotray name; hold on
plotbty name; hold on
plotati name; hold off
%2nd case
shd_file=uigetfile('*.shd');
plotshd 'shd_file'; hold on
plotbty 'name'; hold on
plotati 'name'; hold off
In both cases the functions plotray, plotshd, ... do not recognize the filename stored in the variable but the variable.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 3일
basename = 'a';
dinfo = dir( [basename, '.*'] );
filenames = {dinfo.name};
Now filenames is a cell array of existing file names all with the same basic name but with the different extensions.
  댓글 수: 5
Paschalis Garouniatis
Paschalis Garouniatis 2017년 11월 3일
Is it possible to convert your code for the 1st case in which i don't need the extension of the file? For the second case that i checked it worked.
Walter Roberson
Walter Roberson 2017년 11월 3일
%1st case
file='/home/raptor/Desktop/BELLHOP_LAB/Bellhop_results/Ray_trace/a.ray';
[filepath,name,ext]=fileparts(file);
plotray(name); hold on
plotbty(name); hold on
plotati(name); hold off
%2nd case
shd_file=uigetfile('*.shd');
plotshd(shd_file); hold on
plotbty(name); hold on
plotati(name); hold off

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by