Effacer les filtres
Effacer les filtres

How can I split a vector in a particular way

2 vues (au cours des 30 derniers jours)
Cristian
Cristian le 21 Avr 2013
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).

Réponses (1)

Image Analyst
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
Cristian
Cristian le 22 Avr 2013
Modifié(e) : Cristian le 22 Avr 2013
I think you don't understand me, I don't need the values that are >=0 and <=180, I need the values for alfa=0:10:180 in a vector M_motor1, values for alfa=180:10:360 in a vector M_motor2, values for alfa=360:10:540 in M_motor3, and values for alfa=540:10:720 in M_motor4. The problem for me is that i cannot break the M_motor in 4 equal parts, I need that the last value of M_motor1 that is 0 to be also be the first value in M_motor2. The same for the rest. So every subvector will have 19 values. And in the last part I want to add add the vectors M_motor1,2,3,4 in a M_motor_t. So the first sum in M_motor_t (first value) will be 0, next 7.26 etc. like i wrote above, in my last comment.
Image Analyst
Image Analyst le 22 Avr 2013
So why can't you do
M_motor1 = M_motor(0 : 10 : 180);
and so on??

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by