FileName='C:\Users\Huawei\Desktop\No2_10bit'; f1 = fopen(FileName,'r'); data = fread(f1,'uint16'); fclose(f1); %6652 4435 for i=1:2048 for j = 1:2048 A(i,j) = data((i-1)*2048+j); end end imshow(A/max(A(:)))
时间: 2024-04-15 07:30:33 浏览: 49
根据您提供的代码,您正在从文件中读取数据并将其存储在矩阵 A 中。然后,您想显示矩阵 A 的归一化图像。如果您想在 MATLAB 中实现这个目标,可以尝试以下代码:
```matlab
FileName = 'C:\Users\Huawei\Desktop\No2_10bit';
f1 = fopen(FileName, 'r');
data = fread(f1, 'uint16');
fclose(f1);
A = reshape(data, 2048, 2048);
A_normalized = A / max(A(:));
imshow(A_normalized);
```
这段代码会打开文件,读取数据,并将其重塑为 2048x2048 的矩阵 A。然后,它会对矩阵 A 进行归一化,并使用 `imshow` 函数显示归一化后的图像。请确保文件路径和名称正确,并且文件中的数据按照正确的顺序排列。
相关问题
for ipaddr,ntos,name,pswd,epswd in ip_list: session = ConnectHandler(device_type=ntos, ip=ipaddr, username=name, password=pswd, secret=epswd, port = 22, verbose = True, banner_timeout=300) print("connecting to "+ ipaddr + ntos + name + pswd) print("---- Getting configuration from {}-----------".format(ipaddr)) if ntos == 'huawei': config_data = session.send_command('dis ip int brief ') print (config_data) elif ntos == 'cisco_ios': session.enable() config_data = session.send_command("show vlan") #抓取配置引入config print(config_data) #回显内容,类似登录设备show run else: print("Unsupported OS: " + ntos) continue session.disconnect() return config_data config_data = session.send_command如何执行多条命令,例如display version display cpu-usage display memory-usage这三条命令,然后retun config_data,并且在循环中retun不会中断循环
你可以使用`send_command()`方法来执行多条命令,或者使用`send_command_timing()`方法来逐行输入命令。这里有两种方法可以实现你的需求:
方法一:使用`send_command()`方法
你可以将多个命令组成一个字符串,然后一次性执行它们。在华为设备上,需要使用管道符号“|”将多个命令连接起来:
```python
command = 'display version | display cpu-usage | display memory-usage'
config_data = session.send_command(command)
```
在思科设备上,可以使用分号“;”将多个命令连接起来:
```python
command = 'show version ; show processes cpu sorted ; show memory statistics'
config_data = session.send_command(command)
```
方法二:使用`send_command_timing()`方法
你可以遍历命令列表,逐个输入并执行命令,然后将输出保存到一个字符串中:
```python
commands = ['display version', 'display cpu-usage', 'display memory-usage']
config_data = ''
for cmd in commands:
output = session.send_command_timing(cmd)
config_data += output + '\n'
return config_data
```
这种方法适用于在执行命令时需要等待一些时间的情况,例如需要输入密码或确认信息等。
# _*_ coding:utf-8 _*_ import time import PySimpleGUI as sg import Tools menu_def=[ ['需处理的告警', ['华为GSM告警', '华为45G告警', '爱立信4G告警','---','荆州245告警']], ['现网配置',['4G现网配置','---','5G现网配置','---','GSM现网工参']], ] #3) 创建窗口 # ,location=(0,0), size=(1480,900) window=sg.Window('荆州移动项目工具',layout,resizable=True,keep_on_top=False,finalize=True,size=(720,450),font=('宋体',28)) # 全屏显示 window.maximize() #4) 事件循环 while True: event,values=window.read() #窗口的读取,有两个返回值(1.事件 2.值) #print(event,values) if event==None: #窗口关闭事件 break if event=='': #Cancel关闭事件 break if event == '华为GSM告警': Tools.HWGSM_GJ() if event == '华为45G告警': Tools.HWLNR_GJ() if event == '爱立信4G告警': Tools.ALX_GJ() if event == '荆州245告警': Tools.HW245_GJ() if event == '4G现网配置': Tools.HWLTE_XWPZ() if event == '5G现网配置': Tools.HW5G_XWPZ() if event == 'GSM现网工参': Tools.HWGSM_XWGC() #5) 关闭窗口 window.close() 加载文件、处理文件、保存文件 加入进度条
要在代码中添加进度条来显示文件加载、处理和保存的进度,可以按照以下步骤进行操作:
1. 在`layout`中添加一个进度条控件,例如:
```python
layout = [
[sg.Menu(menu_def)],
[sg.ProgressBar(100, orientation='h', size=(20, 20), key='progressbar')],
# 其他窗口布局代码
]
```
2. 在事件循环中更新进度条的值,并在需要时调用`window.refresh`方法来刷新窗口。具体操作如下:
```python
# 创建进度条变量
progress_value = 0
# 在事件循环中更新进度条
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
if event == '华为GSM告警':
# 重置进度条的值
progress_value = 0
# 加载文件
# 更新进度条的值
progress_value += 25
window['progressbar'].update(progress_value)
window.refresh()
# 处理文件
# 更新进度条的值
progress_value += 25
window['progressbar'].update(progress_value)
window.refresh()
# 保存文件
# 更新进度条的值
progress_value += 25
window['progressbar'].update(progress_value)
window.refresh()
# 其他操作
# 其他菜单选项的处理代码
# 关闭窗口
window.close()
```
在上述代码中,我们首先创建了一个进度条变量`progress_value`来保存进度条的当前值。然后,在点击"华为GSM告警"菜单选项时,我们将进度条的值重置为0,然后依次加载文件、处理文件和保存文件,每完成一步更新一次进度条的值。在更新进度条的值之后,我们使用`window.refresh`方法来刷新窗口,以确保进度条的更新显示。
请注意,以上代码只是一个示例,你需要根据实际的文件加载、处理和保存操作来修改代码。
阅读全文
相关推荐

















