can i use more than one hold on function in same code?

I am dividing an image in four quadrants recursively if they satisfy the condition. For that I am using following code:
figure;
imshow(lf);
div_rec_A(lf,rf,r,c,g1_squ,g2_squ);
function div_rec_A( lf,rf,r,c,g1_squ,g2_squ )
hold on;
xv1=[c/2,c/2];
yv1=[1,r];
line(xv1,yv1,'Color','r','LineWidth',1);
xh1=[1,c];
yh1=[c/2,c/2];
line(xh1,yh1,'Color','r','LineWidth',1);
if condition
%copy the part in another image
else
lf = AL;
rf = AR;
[r c] = size(lf);
g1_squ = AFL;
g2_squ = AFR;
div_rec_A(lf,rf,r,c,g1_squ,g2_squ);
here lf and rf are two images, r and c are dimension of the image and g1_squ and g2_squ are gradient of the lf and rf respectively. AL and RL is image portion of first quadrant of lf and rf images respectively. And AFL and AFR is image portion of first quadrant of g1_squ and g2_squ images respectively.
The above code works well and divides the first quadrant of the image but now I want to divide image of all four quadrants. So I made other three same functions namely div_rec_B(lf,rf,r,c,g1_squ,g2_squ), div_rec_C(lf,rf,r,c,g1_squ,g2_squ), div_rec_D(lf,rf,r,c,g1_squ,g2_squ) because the conditions are different for each quadrant. And all four functions are called in main function sequentially.
The problem is, the division of only first function is displayed. I tried adding
figure;
imshow(lf);
in each function at starting. It shows the result but I want all the divisions to be done on single image. So I guess the hold on function is not holding the image after first function. I didn’t write hold off in any of the function.
I hope the problem is clear. Plz HELP. Thanks in advance.

4 Comments

You can check in the plot browser what has actually been plotted on the axes to check whether the hold status is working correctly.
The body of your question is a little confusing (use '{} Code' for formatting code otherwise it is unreadable), but in answer to the question in the title:
The hold status of an axes is either 'on' or 'off'. You can call 'hold on' and 'hold off' as many times as you like, but repeated calls to 'hold on' will have no effect, good or bad, unless something has turned the hold status off in between calls.
Incidentally it is generally much better to give an explicit axes handle to a hold instruction (or any plotting related function) e.g.
hold( hAxes, 'on' )
otherwise you may be applying the hold status to the wrong axes if you have many.
ok...i have edited the question now. but i don't know how to check in the plot browser window.
actually the first hold on works well and in second, third and fourth function, the result does not seem to be as expected. please refer the comment of answer given by Echidna for figure
thank you...
View -> Plot Browser on your figure will show you a list of all objects plotted on your axes.

Sign in to comment.

Answers (1)

the question is not completly clear (it helps if you would use the code lay-out option so that is better parsed), but it does not seem to make sense to use the hold on option in this case since you only have one image it seems and thus only one axes...
did you try stepping trhough your code to make sure that xv1 and yv1 are calculated correctly for the other quadrants. It could be that the offset is ill-defined causing the lines to be drawn, but not visible to you because outside of visible range.

3 Comments

I am sorry for that. now i have edited the question. what i want is something as following
and it is dividing the image in four parts recursively.
but what i am getting is as following
i am using hold on because the lines are drawn one by one.
I don't know if there is any other method, please suggest.
the xv1 and yv1 are calculated correctly.
thank you in advance...:)
That looks more like a bug in your recursion than a problem with the axes 'hold' status. If the hold status were switched off at any point you would lose the original image which would be a big clue.
Also if that is the first quadrant you calculate rather than the last that also suggests there is not a problem with the hold status.
thank you for making me realize that there is problem with the recursion function only. actually I am passing size of the image. so every time it will take from 1 to 128 if my image size is 256*256.
is there any other way i can pass parameters so that the lines can be drawn as i previously showed.
the other function code is same as first. the only change is in the condition. so xv1,yv1,xh1 and yh1 are same for all.
thanks in advance

Sign in to comment.

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Asked:

on 3 Mar 2015

Commented:

on 5 Mar 2015

Community Treasure Hunt

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

Start Hunting!