Issue plotting data points as text

조회 수: 1 (최근 30일)
Lindsay
Lindsay 2015년 1월 21일
댓글: dpb 2015년 1월 21일
Hi all! I'm trying to plot 10 data points using the subject name (e.g., S22, S29..etc) as the data point label rather than a shape. I think I've done this years ago with sprintf, but cannot get it to work now. Below is an example of my code that includes subject 10. I really appreciate the help.
SUBJECTS = [22 29 38 40 41 42 43 44 46 47];
subjstring = {'S22', 'S29', 'S38', 'S40', 'S41', 'S42', 'S43', 'S44', 'S46', 'S47'};
xlsfile = 'C:\Users\Lindsay\Desktop\CTinfo_Jan_2014.xlsx';
figure;
allthres = [];
allamp = [];
allerb = [];
allwf = [];
for isubj = 1:length(SUBJECTS)
else isubj = 10
qthres = xlsread(xlsfile, subjstring{isubj}, 'J3:J16');
wf = xlsread(xlsfile, subjstring{isubj}, 'H22');
[thresi, thresj, thres] = (find(qthres > 0));
thresmean = mean(qthres(thresi));
end
%store threshold mean values for each subject
allthres = cat(2, allthres, thresmean);
%store wrapping factors for each subject
allwf = cat(2, allwf, wf);
subjlabel = sprintf(subjstring{isubj});
plot (allthres, allwf);
hold on;

답변 (2개)

dpb
dpb 2015년 1월 21일
text(allthres, allwf,subjstring.')
should do it if I understand what you're after.
  댓글 수: 2
Lindsay
Lindsay 2015년 1월 21일
Thanks! This seems to plot all my subjects kind of like a legend. I'm more looking for each of the circles (in the first subplot) to be S22, S38, etc...rather than circles. Thanks!!
dpb
dpb 2015년 1월 21일
What are the variables that give the points that are the circles? Use those as the x,y coordinates to text. I presumed that was what the two variables were in the plot command.
You do want the 'horizontal','center','vertical','middle', btw, to align the middle of the text string at the x,y coordinates.
If you've got multiple values nearby, then you likely will see overlap but it doesn't look like should be with the left plot; not sure about the right--looks like a lot of values outside the axes limits.
Also, of course, I assumed the length() of the string labels matches the number of points to plot; you have to select those that go with each point, of course.

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


Chad Greene
Chad Greene 2015년 1월 21일
Try this:
subjstring = {'S22', 'S29', 'S38', 'S40', 'S41', 'S42', 'S43', 'S44', 'S46', 'S47'};
x = 1:10;
y = rand(size(x));
axis([0 11 -.5 1.5])
text(x,y,subjstring','horiz','center','vert','middle')
  댓글 수: 3
Chad Greene
Chad Greene 2015년 1월 21일
What are the dimensions of allthresh and allwf?
Chad Greene
Chad Greene 2015년 1월 21일
Also, you should not need to plot any circles. Just make sure your axis limits are set to include all your labels because text does not automatically set axis limits as plot does.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by