how to put them text lines into loop to reduce the coding line?

조회 수: 1 (최근 30일)
plot (x,y(1:10:end,:),'Color',[0.4940, 0.1840, 0.5560],'LineStyle','-','LineWidth',1.5);
hold on
text(1.688,0.038,'ola')
text(1.688,0.028,'ola1')
text(1.688,0.02,'ola2')
text(1.688,0.013,'ola3')
text(1.688,0.0076,'ola4')
text(1.688,0.004,'ola5')
text(1.688,0.0015,'ola6')
text(1.688,0,'ola7')
hold all

채택된 답변

Walter Roberson
Walter Roberson 2020년 10월 19일
text(repmat(1.688, 1, 8),[0.038, 0.028, 0.02, 0.13, 0.0076, 0.004, 0.0015, 0], {'ola', 'ola1', 'ola2', 'ol3', 'ol4', 'ola5', 'ola6', 'ola7'})
or
y = [0.038, 0.028, 0.02, 0.13, 0.0076, 0.004, 0.0015, 0];
x = 1.688 * ones(size(y));
str = {'ola', 'ola1', 'ola2', 'ol3', 'ol4', 'ola5', 'ola6', 'ola7'};
text(x, y, str)

추가 답변 (2개)

KSSV
KSSV 2020년 10월 19일
x = rand(9,1) ;
y = rand(9,1) ;
str = strcat(repelem('ola',9,1),num2str((0:8)')) ;
text(x,y,str)

Ameer Hamza
Ameer Hamza 2020년 10월 19일
Try this
yv = [0.038 0.028 0.02 0.013 0.0076 0.004 0.0015 0];
hold on
for i = 1:numel(yv)
text(1.688, yv(i), sprintf('ola%d', i));
end

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by