Effacer les filtres
Effacer les filtres

Choosing not number elements from matrix to use in title figures and plots

1 vue (au cours des 30 derniers jours)
I want to use a list of names to put in titles of plots or figures.
This is the matrix and the code in my try.
sis = 1; % This defines which element of the sismo matrix element to display
sismo = {'1966 EW Lima' ; '1966 NS Lima'; ...
'1970 EW Ancash'; '1970 NS Ancash';...
'1974 EW Enero Lima'; '1974 NS Enero Lima';...
'1974 EW Octubre Lima'; '1974 NS Octubre Lima';...
'2001 EW Arequipa'; '2001 NS Arequipa';...
'2007 EW Ica Callao'; '2007 NS Ica Callao'; ...
'2007 EW Ica'; '2007 NS Ica'};
sismo = sismo(sis);
figure(sprintf('Numero %s',sismo))

Réponse acceptée

ANKUR KUMAR
ANKUR KUMAR le 29 Sep 2018
Modifié(e) : ANKUR KUMAR le 29 Sep 2018
isletter gives the logical values where ever the letter is in your string. Use this is extract only letters and put this as title
clc
clear
sismo = {'1966 EW Lima' ; '1966 NS Lima'; ...
'1970 EW Ancash'; '1970 NS Ancash';...
'1974 EW Enero Lima'; '1974 NS Enero Lima';...
'1974 EW Octubre Lima'; '1974 NS Octubre Lima';...
'2001 EW Arequipa'; '2001 NS Arequipa';...
'2007 EW Ica Callao'; '2007 NS Ica Callao'; ...
'2007 EW Ica'; '2007 NS Ica'};
for i=1:length(sismo)
subplot(3,5,i)
plot(magic(2))
% title(char(regexp(sismo{i},'\d*','Match'))) %title as only numbers
title(sismo{i}(isletter(sismo{i}))) %title as only letters
end
  4 commentaires
ANKUR KUMAR
ANKUR KUMAR le 29 Sep 2018
For figure name, try this,
for i=1:length(sismo)
figure('Name',sismo{i}(isletter(sismo{i})))
plot(magic(2))
% title(char(regexp(sismo{i},'\d*','Match'))) %title as only numbers
% title(sismo{i}(isletter(sismo{i}))) %title as only letters
title(sismo{i}(union(find(isletter(sismo{i})),strfind(sismo{i},' ')))) %is you wish space too in your title
end

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Visual Exploration 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!

Translated by