# how to form a new vector from an old one with a loop

2 views (last 30 days)
Mohammed Lamine Mekhalfia on 20 Aug 2021
Dear All, I hope that you are all well
I hope I will be able to explain my problem as good as it should.
I have three one column vector, the vectors size is m.
I would like to build a new vector let say we name it VectorA, this vector contain the 1st value of Vector 1 and it will repeat the picking the value at a regular step let say 30 from vector until the end.
Then the vector B it will take the second value from the vector 1 and with the same concept and repeated steps.
the number of vectors created equal to the Number of step used to pick values.
if the size of original vector is not devised on the step chosen, the code need to fill the vector constructed with zeros.
##### 2 CommentsShowHide 1 older comment
Mohammed Lamine Mekhalfia on 20 Aug 2021
Hi Rik.
Thanks for the feedback.
well I successfully constructed one vector I call it blade that take the first value of sensor1 then with a constant step (29) he take 500 value from Sensor1 to form Blade1.
Blade2 to blade29 need to use the same but I do not know how to integrate them to that code.
clc
clear all
T = readtable('Results for 400 rpm.xls');
OPR=T.OPR;
OPR= OPR(~isnan(OPR));
OPR=repelem(OPR,n);
Sensor1=T.Sensor1;
Sensor2=T.Sensor2;
Sensor3=T.Sensor3;
Sensor1(Sensor1<OPR(1)) = []
Sensor2(Sensor2<OPR(1)) = []
Sensor3(Sensor3<OPR(1)) = []
size(OPR)
% a=size(OPR)
% b=size(OPR)/29
size(Sensor1)
size(Sensor2)
size(Sensor3)
h=1
for m=0:1:500
y=Sensor1(1+(29*m))
h=h+1
end

### Categories

Find more on Startup and Shutdown in Help Center and File Exchange

R2019a

### Community Treasure Hunt

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

Start Hunting!