Petitioner seeks a writ of habeas corpus on behalf of Rudolph Brown Martinez, an inmate of the California State Prison at Folsom. Martinez is held under a judgment of conviction entered on his plea of guilty of robbery and burglary (Pen. Code, §§211, 459), both of which the court found to be in the first degree. He also admitted that he was armed with a deadly weapon at the time of the *811offenses. The petition charges that his conviction was obtained in violation of his constitutional right to counsel.
It appears from the transcripts of the proceedings in the trial court that Martinez was arraigned and entered a plea of not guilty to the offenses charged in the information on September 4, 1956. At that time he was represented by petitioner as attorney of record. Trial was set for September 27th, but on September 26th the trial was reset for October 22d for the convenience of petitioner. On October 9th Martinez appeared in court without counsel, stated his willingness to proceed without counsel, withdrew his plea of not guilty, entered a plea of guilty, admitted that he was armed with a deadly weapon at the time of the offenses, waived a presentenee report, waived time for sentencing, and agreed that he had no legal excuse to offer why judgment should not be pronounced against him according to law. The court accepted the deputy district attorney’s recommendation that the sentences run concurrently and pronounced judgment accordingly.
Petitioner contends that Martinez did not freely and intelligently waive his constitutional right to counsel at the time he entered his plea of guilty and that his conviction was therefore obtained in violation of that right. (Cal. Const., art. I, § 13; People v. Chesser, 29 Cal.2d 815 [178 P.2d 761, 170 A.L.R. 246]; In re Connor, 16 Cal.2d 701 [108 P.2d 10].) We issued an order to show cause why the writ should not be granted and appointed a referee to take evidence and make findings as to whether Martinez understood his right to counsel and freely waived it when he pleaded guilty on October 9, 1956. The referee found that Martinez understood his right to be represented by counsel on that date, that there was no improper coercion or inducement to elicit the plea of guilty, and that he was mentally competent to waive his right to counsel. Petitioner has filed objections to these findings.
The record of the referee’s hearing discloses that Martinez was informed of his right to counsel at his preliminary examination on August 28th and again when he was brought before the superior court for arraignment on August 30th; that on August 30th he was given a continuance to obtain counsel; that he was present when counsel was appointed for his codefendants after they stated that they had no money; and that at his actual arraignment on September 4th he appeared with counsel and his right to counsel was *812recited to him for a third time. When he entered his plea of guilty he stated in effect that he wished to proceed without his attorney. In the light of these facts, his previous courtroom experience, and his admissions at the referee’s hearing, there can be no doubt that he was well aware of his right to counsel on the date he pleaded guilty.
There is also ample evidence to support the finding that Martinez freely and intelligently waived that right. The allegations that the district attorney threatened him with prosecution as an habitual criminal unless he changed his plea and that he promised him a recommendation of leniency and medical care for alleged narcotic withdrawal "symptoms if he pleaded guilty were directly contradicted by the district attorney, who testified that no such representations were made and that he had never visited the prisoner in jail. There was thus presented a clear-cut question of credibility, which the referee decided adversely to Martinez, and which we find no reason to decide differently. Moreover, there is no credible evidence to support an inference of impropriety on the part of any representative of the state except the fact that Martinez changed his plea without notice to his attorney of record. Martinez’ statement that since he had been caught in the act of robbery, “there was no doubt’’ of his guilt, his knowledge that his codefendants had pleaded guilty and had been promptly sent to prison, and his expressed desire to avoid wasting any more “dead time’’ while awaiting trial, fully explain the change of plea and preclude any inference of coercion or improper inducement.
Finally, in the light of the testimony of the expert medical witness and Martinez' description of his own symptoms, we agree with the referee that there is no substance to petitioner’s claim that Martinez was incapable of intelligently waiving his right to counsel because he was suffering from narcotic withdrawal symptoms at that time.
Although not binding on this court, the findings of fact made by a referee are entitled to great weight. (In re Allen, 47 Cal.2d 55, 57 [301 P.2d 577] ; In re Mitchell, 35 Cal.2d 849, 855 [221 P.2d 689] ; In re De La Roi, 27 Cal.2d 354, 364 [164 P.2d 10].) We have concluded that the foregoing evidence fully supports the referee’s decision and we therefore find that Martinez understood and freely waived his right to counsel on the date he pleaded guilty. Accordingly, the judgment based thereon cannot be set aside on *813the ground that Martinez was deprived of his constitutional right to counsel. The only question remaining, therefore, is whether the violation of certain statutory provisions compels vacating the judgment.
The trial court erred in permitting Martinez to withdraw his plea of not guilty and plead guilty in petitioner’s absence and without his consent so long as he remained attorney of record. The procedure set forth in sections 2841 and 2852 of the Code of Civil Procedure for a change of attorney applies to criminal as well as civil actions. (People v. Bouchard, 49 Cal.2d 438, 440-441 [317 P.2d 971]; see Code Civ. Proc., §§ 22, 24.) Petitioner did not consent to a change of attorney, no notice was given him until after the final judgment, and no order for a change of attorney was entered by the court. Thus petitioner remained attorney of record, and the trial court erred in allowing Martinez to proceed in person. (People v. Merkouris, 46 Cal.2d 540, 554-555 [297 P.2d 999].)
The trial court also erred in accepting a plea of guilty from Martinez without fully complying with section 1018 of the Penal Code.3 The following colloquy shows substantial compliance with the requirement of that section that the defendant state to the court “that he does not wish to be represented by counsel.’' “Mr. Holzauer : [the prosecuting attorney] ... So although Mr. McPherson has represented Mr. Martinez previously, if it is Mr. Martinez’s desire to proceed now in the absence of Mr. McPherson, I can see no objection *814to that. The Coubt : Are you willing to proceed now ? The Defendant: That’s right. Mb. Holzaueb: It is your desire to proceed now? The Defendant : That’s right.’’
There was no adequate compliance, however, with the requirement that the court “first fully inform him of his right to counsel.” It is true that Martinez was told of his right at and prior to his arraignment. The statute, however, was designed to ensure that a defendant appearing without counsel is aware of his right to counsel at the time he pleads guilty. It is not met by instructions given almost six weeks before that time.
Finally, the required finding that “defendant understands his right to counsel and freely waives it” was not expressly made by the trial judge and under the circumstances cannot be implied. Martinez’ change of plea and his wish to proceed without counsel were presented to the trial court with no explanation other than the following statement by the prosecutorwas informed Mr. Martinez wished to be taken into court as early as possible, and I caused an officer to go down to the jail to verify that that was, in fact, Mr. Martinez’s wish and I was assured that he did wish to be taken into court.” The court made no inquiry to discover whether Martinez had the experience and mental capacity to understand his rights or to determine whether his decision was the result of an intelligent choice freely made by him or of improper influences theretofore brought to bear upon him. (Cf. In re Berry, 43 Cal.2d 838, 841-843 [279 P.2d 18], footnote.) Thus there is nothing in the record to suggest an awareness of the statutory requirement, let alone an attempt to comply with it.
We have concluded, however, that since these procedural errors did not result in any deprivation of the constitutional right to counsel, they do not compel vacating the judgment. The only relevant purpose of section 1018 of the Penal Code and sections 284 and 285 of the Code of Civil Procedure is to secure the right to representation by counsel. (See Boca etc. R.R. Co. v. Superior Court, 150 Cal. 153, 156 [88 P. 718]; Board of Commissioners v. Younger, 29 Cal. 147, 150 [87 Am.Dec. 164].) When that right has been freely and intelligently waived, the defendant has not been deprived of any right that the statutes are designed to secure. Vacation of the judgment on habeas corpus under these circumstances would serve only as an admonition to trial courts in *815other cases. That is not a proper function of the writ. (See In re Mclnturff, 37 Cal.2d 876, 880-881 [236 P.2d 574]; In re Lindley, 29 Cal.2d 709, 722-723 [177 P.2d 918]; In re Bell, 19 Cal.2d 488, 492-495 [122 P.2d 22].) It must be presumed that trial courts will ordinarily insist on compliance with these statutory provisions and thereby discourage groundless collateral attacks on final judgments of conviction.
It is true that convictions have been set aside on habeas corpus for failure of the trial court to require compliance with the provision in section 1018 of the Penal Code that a plea must be put in by defendant personally, even though the plea was entered by defendant’s counsel in defendant’s presence and without objection by him. (In re Breen, 162 Cal.App.2d 235 [328 P.2d 465]; In re Brain, 70 Cal.App. 334 [233 P. 390].) If those cases were correctly decided, the judgment should be vacated in the present ease, for there is no more reason in the former than in the latter to vacate the judgment without inquiry as to whether the right secured by the statute had in fact been violated. The purpose of the requirement that a plea be entered by defendant personally is to ensure that the plea is his own. If it is, the purpose of that requirement is accomplished, just as the purpose of the provisions to secure the right to counsel is accomplished when the defendant freely and intelligently waives that right. Accordingly, in those cases the court should not have declared the judgment void without determining that the defendant had not authorized or adopted counsel’s statement of his plea. If he had authorized or adopted counsel’s statement of his plea, no purpose other than admonition was served by setting aside the judgment on habeas corpus. In re Breen, 162 Cal.App.2d 235 [328 P.2d 465], and In re Brain, 70 Cal.App. 334 [233 P. 390], are therefore disapproved to the extent that they hold that a judgment must be vacated even if the defendant authorized or adopted counsel’s statement of his plea.
The petition for habeas corpus is denied, and the order to show cause is discharged.
Gibson, C. J., and White, J., concurred.
Schauer, J., Spence, J., and McComb, J., concurred in the judgment.
“The attorney in an action or special proceeding may be changed at any time before or after judgment or final determination, as follows:
“1. Upon the consent of both client and attorney, filed with the clerk, or entered upon the minutes;
‘ ‘ 2. Upon the order of the court, upon the application of either client or attorney, after notice from one to the other. ...”
“When an attorney is changed, as provided in the last section, written notice of the change and of the substitution of a new attorney, or of the appearance of the party in person, must be given to the adverse party. Until then he must recognize the former attorney.”
‘‘ Unless otherwise provided by law every plea must be put in by the defendant himself in open court. No plea of guilty of a felony for which the maximum punishment is death, or life imprisonment without the possibility of parole, shall be received from a defendant who does not appear with counsel, nor shall any plea of guilty of any other felony be accepted from any defendant who does not appear with counsel unless the court shall first fully inform him of his right to counsel and unless the court shall find that the defendant understands his right to counsel and freely waives it and then, only if the defendant has expressly stated in open court, to the court, that he does not wish to be represented by counsel. ...”