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!