How can I generate subplots from a loop and name each one?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Fercho_Sala
el 27 de Abr. de 2021
Comentada: Jan
el 27 de Abr. de 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
0 comentarios
Respuesta aceptada
Jan
el 27 de Abr. de 2021
Editada: Jan
el 27 de Abr. de 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 comentarios
Jan
el 27 de Abr. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Subplots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!