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