필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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))

채택된 답변

ANKUR KUMAR
ANKUR KUMAR 2018년 9월 29일
편집: ANKUR KUMAR 2018년 9월 29일
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
ANKUR KUMAR
ANKUR KUMAR 2018년 9월 29일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by