How can I split a vector in a particular way
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello. I have this sequence:
nn=length(0:10:720);
M_motor=zeros(nn,1);
for alfa=0:10:720
cont=alfa/10+1;
cos_alfa=cosd(alfa);
alfa_cont(cont)=alfa;
x(cont)=S*((1-cos_alfa)/2+lambda_prim/4-(lambda_prim/4)*cos_alfa^2);
if (alfa<=180)
P(cont)=pa;
elseif (alfa<=360)
P(cont)=k1/((x(cont)+s)^mc);
elseif (alfa<=540)
P(cont)=k2/((x(cont)+s)^md);
else
P(cont)=pr;
end
beta2(cont)=asind(lambda2*sind(alfa));
F_alfa(cont)=((P(cont)-p0)*Ap/100)+(-(mj*r_maniv*((pi*n/30)^2)*(cosd(alfa)+lambda2*cosd(2*alfa)))/10000);
M_motor(cont)=(F_alfa(cont)*(sind(alfa+beta2(cont))/cosd(beta2(cont)))*r_maniv)/1000;
end
How can i break M_motor in 4 parts(subvectors) like this: M_motor1=values from 0-180 M_motor2=values from 180-360 M_motor3=values from 360-540 M_motor4=values from 540-720 Notice that the last value is the first value in the next vector, and then i want to add them all together like this: M_motor_t=M_motor1+M_motor2+M_motor3+M_motor4 (vector contains 19 values).
0 commentaires
Réponses (1)
Image Analyst
le 21 Avr 2013
You can extract values of M_motor into separate variables like this:
% Create sample data:
M_motor = randi(740, 1,50)
% Now start extracting ranges.
indexesToExtract = M_motor > 0 & M_motor <= 180;
M_motor1 = M_motor(indexesToExtract)
indexesToExtract = M_motor > 180 & M_motor <= 360;
M_motor2 = M_motor(indexesToExtract)
indexesToExtract = M_motor > 360 & M_motor <= 540;
M_motor3 = M_motor(indexesToExtract)
indexesToExtract = M_motor > 540& M_motor <= 720;
M_motor4 = M_motor(indexesToExtract)
% Combine all together
M_motor_t = [M_motor1, M_motor2, M_motor3, M_motor4]
6 commentaires
Image Analyst
le 22 Avr 2013
So why can't you do
M_motor1 = M_motor(0 : 10 : 180);
and so on??
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!