How can I generate subplots from a loop and name each one?

1 次查看(过去 30 天)
Hello everyone. I was trying to generate subplots (2x2) and name each plot according with its specific dataset without any success, how can I do it? , here is the code, thanks for your help.
for cv=1:numel(C1)
ax1 = axes('Parent',figure);
imagesc(x,y,(C1{1,cv}));
ax1.YAxis.Direction = 'normal';
title('Power [dB]');
xlabel('LT 30 minutes (???)','FontSize',9,'color','default'); %'LT 30 minutes (name of the dataset)'
ylabel('altitude (km)','FontSize',9,'color','default');
ylim([78.3 95]);
xticklabels('');
colormap jet;
col = colorbar;
col.Label.String = '[dB]';
end

采纳的回答

Jan
Jan 2021-4-27
编辑:Jan 2021-4-27
FigH = figure;
for cv = 1:numel(C1)
ax1 = subplot(2, 2, cv, 'Parent', FigH); % [EDITED]
imagesc(x,y,(C1{1,cv}));
ax1.YAxis.Direction = 'normal';
title('Power [dB]');
name = sprintf('LT 30 minutes (%d)', cv); % Maybe?
xlabel(name,'FontSize',9,'color','default');
ylabel('altitude (km)','FontSize',9,'color','default');
ylim([78.3 95]);
xticklabels('');
colormap jet;
col = colorbar;
col.Label.String = '[dB]';
end
How are the names of the data sets stored? In a cell string? Then:
name = sprintf('LT 30 minutes (%s)', NameList{cv});
  4 个评论
Jan
Jan 2021-4-27
Now I download the file, start Matlab, load the file into a variable to understand, what you mean. It is more efficient, if you explain it directly. The File C1.mat contains a variable called "C1". Anywhere in the code you have loaded the MAT file. Then store the name to use it, when you need it.
Do not use a load() without storing the output in a variable, but catch it:
FileData = load(FileName);
Then it is easy to obtain the name later:
NameList = fieldnames(FileData);
Name = NameList{1};
Value = FileData.(Name);
Then you do not need to access "C1", but you are free to use the code to process the contents of any MAT file. The idea is not to hide information in the name of the variables, as value of variables.

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by