I'm writing my Rsquared values onto a scatter plot but they don't appear on the correct suplot!

4 次查看(过去 30 天)
I've managed to print my Rsquared values onto scatter subplots but for some reason it's shifted each value onto the wrong graph by one. I have 8 graphs and the last graph for some reason doesn't get an Rsquared value printed on it!
My code for this part is:
for j = 2:9 %change 9 to 8 when removing one KPI
y = T{:,j};
R = corrcoef(x,y);
R_squared = R(2)^2;
text(5, 5, ['R^2 =' num2str(R_squared)]);
ax = subplot(2,4,(j-1));
scatter(ax,x,y,'filled');
lsline(ax);
ylim([0,max(y+10)]);
xlim([0,8]);
xlabel('League Score');
ylabel(T.Properties.VariableNames{(j)});
end;
So obviously the text part is what prints the rsquared values to my graphs.
Thank you!!

采纳的回答

Geoff Hayes
Geoff Hayes 2015-10-17
Olivia - the problem may be because you are not specifying which axes to write the text to. According to the documentation, the text is written to the current axes and so you will have to specify which axes is the current one before you invoke text. (It may be that on subsequent iterations of your loop, the current axes is always the last one updated.) Try doing the following in your loop
ax = subplot(2,4,(j-1)); % get the axes
axes(ax); % set ax as the current axes
text(5, 5, ['R^2 =' num2str(R_squared)]);
scatter(ax,x,y,'filled');
% etc.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by