Note: The text appears in stupid places in the code above, because the data are random, but the positions make sense in my code. I am just interested to know how to print one label per plot!
Add text to plot using a loop
조회 수: 6 (최근 30일)
이전 댓글 표시
I am plotting FTIR data. The code below should work, but I have substituted in randomly generated data.
I'd like the text function in the loop to produce a label for each plot. i.e., p1(1) will be labelled pre-sorption, and p1(5) will be labelled 'SiO2 = 2 mM'. Currently, the code produces text in the right position, but all five labels appear at all five locations. How do I modify the code to make sure each label appears sequentially?
Thanks!
AM_cm=([400:1:4000]);
AM_cm=AM_cm.';
AM=([rand(3601, 1) rand(3601, 1) rand(3601, 1) rand(3601, 1) rand(3601, 1)]);
figure(1);
set(gca,'Xdir','reverse');
set(gca,'ytick',[]); set(gca,'yticklabel',[]);
xlabel ('cm-1','Fontsize', 14); ylabel ('Absorbance','Fontsize', 14);
for a = 1:5% FTIR data
hold on; box on;
p1(a)=plot(AM_cm,AM(:,a),'-','LineWidth',2);
text(3900, AM(1,a),['pre-sorption','SiO2= 0.5 mM','SiO2 = 1 mM','SiO2 = 1.5 mM','SiO2 = 2 mM'],'Fontsize', 12);
end
댓글 수: 3
채택된 답변
Walter Roberson
2023년 8월 22일
AM_cm=([400:1:4000]);
AM_cm=AM_cm.';
AM=([rand(3601, 1) rand(3601, 1) rand(3601, 1) rand(3601, 1) rand(3601, 1)]);
figure(1);
set(gca,'Xdir','reverse');
set(gca,'ytick',[]); set(gca,'yticklabel',[]);
xlabel ('cm-1','Fontsize', 14); ylabel ('Absorbance','Fontsize', 14);
labels = {'pre-sorption','SiO2= 0.5 mM','SiO2 = 1 mM','SiO2 = 1.5 mM','SiO2 = 2 mM'};
for a = 1:length(labels)% FTIR data
hold on; box on;
p1(a)=plot(AM_cm,AM(:,a),'-','LineWidth',2);
text(3900, AM(1,a),labels{a},'Fontsize', 12);
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!