我想重现从新图的数字到子图的情节。请考虑以下
f1 = figure;
p1 = plot([1 2],[1 2], 'r');
legend(p1, 'Test')
f2 = figure;
p2 = plot([2 3], [2 3], 'g');
f3 = figure;
h1 = subplot(1,2,1);
h2 = subplot(1,2,2);
现在,我的目的是将p1
和p2
复制为f3
的子图。我尝试过许多组合,包括以下内容,但没有效果
ax1 = copyobj(f1.Children, h1);
ax2 = copyobj(f2.Children, h2);
this link对类似问题的回答没有帮助。我正在使用R2016b。
答案 0 :(得分:0)
这对我有用:
#Imports
import time
import random
#If more than 7 letters and numbers
def CheckPlate(np):
IsPlateValid = False
if len(np) != 7:
print("Invalid Plate Number!")
else:
IsPlateValid = True
return IsPlateValid
#If less than 7 letters and numbers outputs number plate and speed
def CheckPlateContent(twoletters, twonumbers, threeletters):
twoletterstf=False
twonumberstf=False
threeletterstf=False
valid = False
for letter in twoletters: #I have to use (for x in Xs) because of array input but your format should work fine here if input is user input
if letter.isupper() and letter.isalpha():
twoletterstf = True
for number in twonumbers:
if number.isdigit():
twonumberstf = True
for letter in threeletters:
if letter.isupper() and letter.isalpha():
threeletterstf = True
if (twoletterstf == True and twonumberstf == True and threeletterstf == True):
valid= True
else:
print("Invalid Plate Number!")
return valid
def SpeedCheck(speed):
ticket = False
ticketprice = 0
if speed >= 31:
ticket=True
ticketprice=100+speed
return ticket, ticketprice
def main():
#Gets the number plate
np=['A','C','4','2','F','G','H'] #input is an array because I id this on Atom and there is no input console.
#Sets the parts of the license plate
twoletters=np[0:2]
twonumbers=np[2:4]
threeletters=np[4:7]
#Sensors
sensor1=0
sensor2=random.uniform(0.25, 0.4)
sensor2=round(sensor2, 1)
#Variables
speed=0
ticketprice=0
ticket=False
distance=10
#Calculations to work out the speed
time.sleep(1)
distance=10
times=sensor2-sensor1
ans=1/times
speed=distance*ans
bool = CheckPlate(np)
valid = CheckPlateContent(twoletters, twonumbers, threeletters)
ticket, ticketprice = SpeedCheck(speed)
print ("Number Plate:" + str(np) + "\n")
print ("Valid:" + str(valid) + "\n")
print ("Speed:" + str(speed) + "M/S" + "\n")
print ("Ticket:" + str(ticket) + "\n")
print ("Ticket Price: £" + str(ticketprice) + "\n")
if __name__ == "__main__":
main()
图3显示了两个子图,其中包含p1和p2中的数据: