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

2 次查看(过去 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 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by