Using hold to generate scatter-histogram in for loop

I'm attempting to combine multiple scatter-histograms into one figure. I have randomly assigned y-values for each x-value. I've tried adding 'hold' and 'hold on' before and within the for loop. Matlab keeps outputting individual figures. Any help would be great!
a=1; b=10;
for i=1:MiceNumb
xData=0;
yData=0;
xData = xDataCellArray{i};
r=(b-a).*rand(5000,1) + a;
yData=r(1:size(xData));
figure
if genotype(1,i)==1
scatterhist(xData,yData,'Kernel','on','LineStyle',{'-'},'Marker','.');
end
end

 채택된 답변

Adam Danz
Adam Danz 2025년 4월 2일

0 개 추천

There are two approaches to creating a scatterhistogram while using a loop.
The first is to collect the data within the loop and then plot it afterwards. You'll likely need to create a grouping variable to keep track of which loop the data came from. Then use the following syntax where the arguments are vectors.
The second approach would be to produce the scatterhistogram at the beginning and then append its data properties. That approach is demonstrated in this comment: https://www.mathworks.com/matlabcentral/answers/1770655-how-to-hold-different-constellations-using-scatterhistogram#comment_3330674

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2017년 9월 6일

답변:

2025년 4월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by