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

1 view (last 30 days)
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))

Accepted Answer

ANKUR KUMAR
ANKUR KUMAR on 29 Sep 2018
Edited: ANKUR KUMAR on 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 Comments
ANKUR KUMAR
ANKUR KUMAR on 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

Sign in to comment.

More Answers (0)

Categories

Find more on Visual Exploration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!