# MATLAB: I nee to change this str2double code while keeping the same output for the collatz function.

## MATLAB: I nee to change this str2double code while keeping the same output for the collatz function.

functionMATLABstring

The following is the script to my function:
``function [steps,maxnum]=collatz(num)str=input('Enter an integer greater than 1:','s');num=str2double(str);cnt=0;maxnum=num;while num>1    cnt=cnt+1;    if mod(num,2);        num=num*3+1;    else        num=num/2;    end    if num>maxnum; maxnum=num;    endends=cntmaxnum``
I was told that I cannot use the str2double(str) function but I cannot figure out how to get the same output any other way. My script is supposed to take a number greater than 1 and apply a while loop by multiplying the integer by 3 then adding 1 if it is odd or dividing it by 2 if it is an even number until the function equals 1, where the loop ends. I need a different method for finding the steps it takes for the loop to end. For example if the user enters “3” the steps would be 3 → 10 → 5 → 16 → 8 → 4 → 2 → 1. I would need the output to be s=7 %meaning it took 7 steps to complete the loop m=16 %representing the maximum number reached during the loop

• ``str = input('Enter an integer greater than 1:','s');num = sscanf(str,'%i');``