Hi guys, i want to ask something since im still new using matlab..how can i iterate loop from negative variable to its positive variable?..and do you guys know anything about appearing a GIS/google earth into GUI?
Mostra commenti meno recenti
for xj= 1 : xj
[x1r,x1m] = calX(xj,x1,yj,y1,i1,angle1);
[x2r,x2m] = calX(xj,x2,yj,y2,i2,angle2);
[x3r,x3m] = calX(xj,x3,yj,y3,i3,angle3);
[x4r,x4m] = calX(xj,x4,yj,y4,i4,angle4);
[x5r,x5m] = calX(xj,x5,yj,y5,i5,angle5);
[x6r,x6m] = calX(xj,x6,yj,y6,i6,angle6);
totalXr = calTotalX( x1r, x2r, x3r, x4r, x5r, x6r);
totalXm = calTotalX( x1m, x2m, x3m, x4m, x5m, x6m);
magX = sqrt(((totalXr)^2) + ((totalXm)^2));
thetaX = atand(totalXm/totalXr);
Bjx = convert_meter_to_feet(magX);
[y1r,y1m] = calY(xj,x1,yj,y1,i1,angle1);
[y2r,y2m] = calY(xj,x2,yj,y2,i2,angle2);
[y3r,y3m] = calY(xj,x3,yj,y3,i3,angle3);
[y4r,y4m] = calY(xj,x4,yj,y4,i4,angle4);
[y5r,y5m] = calY(xj,x5,yj,y5,i5,angle5);
[y6r,y6m] = calY(xj,x6,yj,y6,i6,angle6);
totalYr = calTotalY( y1r, y2r, y3r, y4r, y5r, y6r);
totalYm = calTotalY( y1m, y2m, y3m, y4m, y5m, y6m);
magY = sqrt(((totalYr)^2) + ((totalYm)^2));
thetaY = atand(totalYm/totalYr);
Bjy = convert_meter_to_feet(magY);
omega = atand((((Bjx)^2)* sind(2*thetaX) + ((Bjy)^2)* sind(2*thetaY))/(((Bjx)^2)* cosd(2*thetaX) + ((Bjy)^2)* cosd(2*thetaY)));
Bjxmax = omega + thetaX;
Bjymax = omega + thetaY;
Bjxmin = omega + thetaX + 90;
Bjymin = omega + thetaY + 90;
BjMAX = sqrt(((Bjx*cosd(Bjxmax))^2) + ((Bjy*cosd(Bjymax))^2));
BjMIN = sqrt(((Bjx*cosd(Bjxmin))^2) + ((Bjy*cosd(Bjymin))^2));
Bresult = sqrt((BjMAX^2) + (BjMIN^2));
values_of_field(xj) = Bresult;
value_of_xj_neg(xj) = -xj;
value_of_xj_pos(xj) = xj;
end
Risposta accettata
Più risposte (2)
Image Analyst
il 7 Set 2014
Sure. Just set the starting and ending values, and the step, which will be negative to go from higher numbers to lower numbers:
for k = startingValue : -1 : endingValue
startingValue can be positive or negative, and the same for endingValue. If starting value >= endingValue, you will enter the loop otherwise the loop will not be entered. For example
for k = 8 : -1 : -27
2 Commenti
dpb
il 7 Set 2014
Excepting it looks like OP's query had to do with floating point values where often newbies want to do sotoo--
for xj=-pi:0.05:pi
...
Bresult=some calculations for values of xj
...
values_of_field(xj) = Bresult;
end
The last line in the above loop was extracted from OP's code identically...which is why gave the previous result. Actually, for the above I neglected to add the alternative solution
idx=0; % initialize an index for the array addressing
for xj=-pi:0.05:pi
...
Bresult=some calculations for values of xj
...
idx=idx+1; % increment the array index
values_of_field(idx) = Bresult;
end
Image Analyst
il 7 Set 2014
Yes. I'm sure your answer is the more comprehensive one - I didn't dig into his code as deeply as you. I was just answering the simple question of how you can iterate in the negative direction (backwards), but maybe he wasn't asking that.
syakirin
il 8 Set 2014
0 voti
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!