for i=1:1:4
T=[(cos(x(i)))^2 (sin(x(i)))^2 2*(cos(x(i)))*(sin(x(i)));(sin(x(i)))^2 (cos(x(i)))^2 -2*(cos(x(i)))*(sin(x(i))) ;-(cos(x(i)))*(sin(x(i))) (cos(x(i)))*(sin(x(i))) (cos(x(i)))^2-(sin(x(i)))^2 ;];
XXXXX=inv(T)*Qq*R*T*inv(R);
end
我想根据XXXXX
命名i
;我的意思是,当i=1
投放时,XXXXX
将变为Q1
,而i=2
将为Q2
,并且会一直开启。
答案 0 :(得分:2)
possible but not recommended使用变量名称Q1 Q2 Q3。该链接既解释了为什么不推荐它以及如何实现它。
相反,请使用cell array来存储结果:
class Player(pygame.sprite.Sprite):
def __init__(self,x,y,width = 65, height = 35):
pygame.sprite.Sprite.__init__(self)
self.x = x
self.y = y
self.hspeed,self.vspeed = 0,0
self.images=[]
r0 = pygame.image.load("Images\Player\i1.png")
r1 = pygame.image.load("Images\Player\i2.png")
r2 = pygame.image.load("Images\Player\i3.png")
r3 = pygame.image.load("Images\Player\i4.png")
self.hurt = pygame.image.load("Images\Player\Hurt.png")
self.images.append(r0)
self.images.append(r1)
self.images.append(r2)
self.images.append(r3)
self.rotatedimages = []
rr0 = pygame.transform.flip(r0 ,True, False)
rr1 = pygame.transform.flip(r1 ,True, False)
rr2 = pygame.transform.flip(r2 ,True, False)
rr3 = pygame.transform.flip(r3 ,True, False)
self.rotatedimages.append(rr0)
self.rotatedimages.append(rr1)
self.rotatedimages.append(rr2)
self.rotatedimages.append(rr3)
self.gravity = 0.25
self.index = 0
self.image = self.images[self.index]
self.rect = pygame.Rect(self.x,self.y,width,height)
self.TimeNum=0
self.TimeTarget=10
self.Timer = 0
self.collision = False
def Level1PlatColl(self, BlockListGrass, TrapList, enemygroup, PowerUps):
PlatformCollision = pygame.sprite.spritecollide(self, BlockListGrass, False )
#for each_object in PlatformCollision:
#if self.vspeed > 0:
#self.rect.bottom = each_object.rect.top
#if self.vspeed < 0:
#self.rect.top = each_object.rect.bottom
#self.vspeed = 0
if PlatformCollision:
self.vspeed = 0
if not PlatformCollision:
self.vspeed -= self.gravity
self.rect.y -= self.vspeed
def Jump(self):
key = pygame.key.get_pressed()
if key[pygame.K_UP]:
self.vspeed = 8
self.rect.y -= self.vspeed