title according to the file name

조회 수: 44 (최근 30일)
Fercho_Sala
Fercho_Sala 2021년 4월 15일
댓글: Rik 2022년 3월 24일
Does anybody know how to (in a plot) put the ‘title’ as the name of the file where the X,Y,Z variables are included? the idea is to generate several and independent plots, based on ‘imagesc’, ‘contolchart’ and other plotting functions. Thanks.
  댓글 수: 4
John Ostrander
John Ostrander 2022년 3월 24일
@Rik I am looking for something similar. There is a python code for it (I am learning both and very much a newbie) but in my case and I suspect the qeustion is the same:
C:\path\morepath\.......\filename.csv some of my files are buried deep in the file structure.
Strip "filename" from this automatically and insert it as the graph title.
I work with many files, and many graphs look alike. This would save time.
Rik
Rik 2022년 3월 24일
The fileparts function should do what you need:
[p,f,e]=fileparts('C:\path\morepath\filename.csv')
p = 0×0 empty char array
f = 'C:\path\morepath\filename'
e = '.csv'
%(these results are on Linux, on Windows you should get this)
p = 'C:\path\morepath'
f = 'filename'
e = '.csv'

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

채택된 답변

Constantino Carlos Reyes-Aldasoro
Perhaps you want to add values to the titles of your figures, try something like this
for k=1:9
subplot(3,3,k)
title(strcat('Subplot number =',num2str(k)))
end
If this does not answer your question, we would need more information.
  댓글 수: 1
Adam Danz
Adam Danz 2021년 4월 15일
or,
title(['Subplot number = ', num2str(k)])
or,
title(sprintf('Subplot number = %d', k))

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

추가 답변 (1개)

Chunru
Chunru 2021년 4월 15일
filename = "abc";
load(filename, "x", "y");
plot(x, y)
title(sprintf("File name: %s", filename));
  댓글 수: 1
Rik
Rik 2021년 4월 15일
You shouldn't encourage loading variables like this. Always load to a struct:
S=load(filename, "x", "y");x=S.x;y=S.y;

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

카테고리

Help CenterFile Exchange에서 Title에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by