将以下python语言转换为matlab语言,要求输出的内容相同:import numpy as np import openpyxl # 初始 化 参数 answer = [ ] b_values = range (250 , 360 , 1) # 计算每个 b 值下的 y值 , 并存储到 answer 列表中 for b in b_values : y = 0.0 x0 = 0.2 for i in range (0 , 100): y = b / 100 ∗ x0 ∗ (1 − x0 ) x0 = y answer . append ( y ) # 将 answer 列表 转 换成NumPy数组 answer = np . array ( answer ) # 将 数 据 转 换 成 二 维 数 组 形 式 data = np . zeros ((100 , 110)) for i , b in enumerate( b_values ) : data [ : , i ] = answer [ i ∗ 100: i ∗ 100 + 100] # 将数 据 写入 Excel 表格 workbook = openpyxl . Workbook ( ) worksheet = workbook . a c t i v e for row in data : worksheet . append ( row . t o l i s t ( ) ) workbook . save ( ’ data . xlsx ’ )
时间: 2023-06-24 21:09:07 浏览: 124
Python Numpy 数组的初始化和基本操作
import openpyxl
import numpy as np
answer = []
b_values = range(250, 360, 1)
for b_index, b in enumerate(b_values):
y = 0.0
x0 = 0.2
for i in range(0, 100):
y = b / 100 * x0 * (1 - x0)
x0 = y
answer.append(y)
answer = np.array(answer)
data = np.zeros((100, 110))
for i, b in enumerate(b_values):
data[:, i] = answer[i*100:i*100+100]
workbook = openpyxl.Workbook()
worksheet = workbook.active
for row in data:
worksheet.append([int(i) for i in row])
workbook.save('data.xlsx')
阅读全文