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
0 件のコメント
採用された回答
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
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 件)
参考
カテゴリ
Help Center および File Exchange で Subplots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!