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

1 Ansicht (letzte 30 Tage)
Fercho_Sala
Fercho_Sala am 27 Apr. 2021
Kommentiert: Jan am 27 Apr. 2021
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

Akzeptierte Antwort

Jan
Jan am 27 Apr. 2021
Bearbeitet: Jan am 27 Apr. 2021
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 Kommentare
Fercho_Sala
Fercho_Sala am 27 Apr. 2021
it is jus an array, like the one attached.
Jan
Jan am 27 Apr. 2021
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by