Issue plotting data points as text

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;

Answers (2)

text(allthres, allwf,subjstring.')
should do it if I understand what you're after.

2 Comments

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!!
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.

Sign in to comment.

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

Thanks Chad! I tried that and it's close, but I still have to plot the circles or it plots in a crazy line, and for some reason it seems to be overlapping.
plot (allthres, allwf, 'o');
text(allthres, allwf, subjstring{isubj}, 'horiz', 'center', 'vert', 'middle');
hold on;
ylabel('Wrapping Factor (%)');
xlabel ('Mean Quadrupolar Threshold');
What are the dimensions of allthresh and allwf?
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.

Sign in to comment.

Asked:

on 21 Jan 2015

Commented:

dpb
on 21 Jan 2015

Community Treasure Hunt

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

Start Hunting!