how to crop image in matlab using only for loop? [duplicate] - matlab

This question already has an answer here:
Zoom and Crop Image (Matrix)
(1 answer)
Closed 7 years ago.
i made it with Matrix.how can i make it with for loop
crop.m
function s=crop(f,m,n,x,y)
s=f(x:x+m,y:y+n);

this is code
crop1.m
function s=crop1(f,m,n,x,y)
for i=x:1:x+m
for j=y:1:y+n
s(i-x+1,j-y+1,:)=f(i,j,:);
end
end

Related

save the file with loop index in matlab [duplicate]

This question already has answers here:
How to save each file in a for loop using matlab
(1 answer)
save each data in loop as text file in matlab
(1 answer)
Save images in a loop with variable file names?
(2 answers)
Closed 10 months ago.
I want to save some variables in matlab program like
for i =1:10
x(i)=randn()*5;
save(i,x(i));
end
At every iteration 'i' I want it save the values of x(i), but matlab gives me the error "Error using save Must be a string scalar or character vector." How can I solve this

How to make MATLAB start the xtick from the very beginning? [duplicate]

This question already has answers here:
limit the axes for plotting in Matlab [duplicate]
(2 answers)
Closed 3 years ago.
I am plotting with MATLAB and make MATLAB to put 15 xticks on the x-label. The first xtick doesn't start from the very beginning, though.
xticks([1:15]);
xticklabels({'(1, 2)','(1, 3)','(2, 3)','(1, 4)','(2, 4)','(3, 4)','(1, 5)','(2, 5)','(3, 5)','(4, 5)',...
'(1, 6)', '(2, 6)', '(3, 6)', '(4, 6)', '(5, 6)'});
All you need is: xlim([1:15]);

How to comment a block in MATLAB, similar in C /**/ [duplicate]

This question already has answers here:
How can I do group commenting without commenting each line in MATLAB?
(5 answers)
Closed 6 years ago.
I want to know how to comment a block in MATLAB. I know that in the C language I use / *; But I could not find out about MATLAB.
You can comment out MATLAB blocks with
%{
Comments go here
%}
Outside comment

imwrite matlab "You may not have write permission." [duplicate]

This question already has an answer here:
I am encountering an error while using imwrite
(1 answer)
Closed 7 years ago.
I have this with imwrite in matlab it says: "You may not have write permission." I tried to change the format of the image but It doesn't work.
Check to see if that file already exists and is open somewhere outside MATLAB. It will fail if it is.

How to vectorize a loop in matlab [duplicate]

This question already has answers here:
Structure initialization with repmat
(2 answers)
Closed 9 years ago.
I want to use a function repmat to write this code:
for j=1:30
for i=1:10
myObject{i,j}.s = zeros(6,1);
end
end
I cannot understand how to do that for cells. Can anyone help me please?
You can use deal:
[myObject{1:10,1:30}] = deal( struct('s',zeros(6,1) );
PS: It is best not to use i and j as variables in Matlab.