Issue plotting data points as text
2 views (last 30 days)
Show older comments
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;
0 Comments
Answers (2)
dpb
on 21 Jan 2015
text(allthres, allwf,subjstring.')
should do it if I understand what you're after.
2 Comments
dpb
on 21 Jan 2015
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
on 21 Jan 2015
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 Comments
Chad Greene
on 21 Jan 2015
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.
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!