# Cycle of operations on vector sections

3 views (last 30 days)
Lev Mihailov on 4 Apr 2022
Commented: Lev Mihailov on 4 Apr 2022
I'm trying to make a cycle that would process a section of the vector and return this section to me changed
x=rand(1,2302)
y=rand(1,2302)
step=100;
for i=1:size(x,2)
i1=y(i:i+step);
i2=x(i:i+step);
a(i)=myfun(i1,i2);
end
%% for example my function
function [m,s] = myfun(x,y)
n = length(x);
m = x-0.26;
s= y-0.77
end
##### 2 CommentsShowHide 1 older comment
Lev Mihailov on 4 Apr 2022
@Davide Masiello I added an example function

Davide Masiello on 4 Apr 2022
The problem is myfun spits out two vectors of size 1 x step+1.
You could assign this vectors to the rows of a new matrix (see a and b in the example below) .
x = rand(1,2302);
y = rand(1,2302);
step = 100;
for i = 1:size(x,2)-step
i1 = y(i:i+step);
i2 = x(i:i+step);
[a(i,:),b(i,:)] = myfun(i1,i2);
end
function [m,s] = myfun(x,y)
n = length(x); % <--- not needed
m = x-0.26;
s= y-0.77;
end
Lev Mihailov on 4 Apr 2022
@Davide Masiello just now I noticed this, and my function returns me the same vector (but changed), but why is it a matrix and not a vector?

### Categories

Find more on Matrices and Arrays in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!