How to: Vary the variable name
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a working code but i want it to make shorter.
In the following code i set the x limits.
this code is repeated three times (original code is longer). The only thing that changes is the number Minimum1,2,3 (for 3 subplots).
I tried this Minimum'double2str(k)' etc but that didnt work :)
for k=1:3
Minimum1=str2double(get(handles.MIN_Input1,'String'));
Maximum1=str2double(get(handles.MAX_Input1,'String'));
if ~isnan(Minimum1)
set(subplot(1,3,1),'xlim',[Minimum1 Inf]);
end
if ~isnan(Maximum1)
set(subplot(1,3,1),'xlim',[-Inf Maximum1]);
end
if (~isnan(Minimum1))&&(~isnan(Maximum1))
set(subplot(1,3,1),'xlim',[Minimum1 Maximum1]);
end
end
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 2 Jan 2013
Modifié(e) : Azzi Abdelmalek
le 2 Jan 2013
for k=1:3
Minimum1=str2double(get(handles.MIN_Input1,'String'));
Maximum1=str2double(get(handles.MAX_Input1,'String'));
if isnan(Minimum1)
Minimum1=-Inf
end
if isnan(Maximum1)
Maximum1=Inf
end
set(subplot(1,3,k),'xlim',[Minimum1 Maximum1]);
end
% To generate names use
k=3;
name=sprintf('Minimum%d',k)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Subplots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!