title according to the file name

27 次查看(过去 30 天)
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.
  2 个评论
Fercho_Sala
Fercho_Sala 2021-4-15
for the case you upload a data file and need to title the chart as the original name of the file found in some specific folder i.e C:\Users\Mat\Desktop\matrix_A.dat , obviously without the '.dat' extencion.

请先登录,再进行评论。

采纳的回答

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;

请先登录,再进行评论。

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by