MATLAB Answers

# Matlab Function from code

1 view (last 30 days)
marie lasz on 22 Sep 2020
Commented: Star Strider on 22 Sep 2020
Hello Experts;
I am new in matlab and trying to learn how we can create function? For Example . I have this code how I can create function file out of it? It will be easy for me to learn from this code.
g=imread('cameraman.tiff');
original=g;
[m,n]=size(g);
subplot(2,2,1)
imshow(g,[])
[m,n]=size(g);
a = 3;
b = 3;
num_iter = 5;
for k=1:num_iter
for i=1:m
for j=1:n
r = mod([round(abs(1-(a*(i^4))+j)),round(abs(b*i))],[m n]);
x(i,j)=g(r(3)+1,r(4)+1);
end
end
g=x;
end
subplot(2,2,2)
imshow(x);

#### 0 Comments

Sign in to comment.

### Accepted Answer

Star Strider on 22 Sep 2020
See the documentation on Function Basics.

#### 9 Comments

Show 6 older comments
Steven Lord on 22 Sep 2020
In addition to what Star Strider has said, if you're not sure if your code is behaving correctly I recommend stepping through it line by line, checking that each line does what you expect it to do. The debugging tools in MATLAB will let you do this. Set a breakpoint on the first line, run your code, and step through the file.
marie lasz on 22 Sep 2020
thanks for your suggestions and finally, I did it successfully and learned :-)
Star Strider on 22 Sep 2020
Our pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!

Translated by