I'm writing my Rsquared values onto a scatter plot but they don't appear on the correct suplot!
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Olivia Milton-thompson
il 17 Ott 2015
Commentato: Olivia Milton-thompson
il 17 Ott 2015
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!!
0 Commenti
Risposta accettata
Geoff Hayes
il 17 Ott 2015
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Discrete Data Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!