Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
sparrowzz
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
sgool
sparrowzz
Commits
94bfd925
Commit
94bfd925
authored
Jul 19, 2025
by
NanaSwan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: change to UTF-8 format
parent
9d32971e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
12 行增加
和
12 行删除
+12
-12
rspower/data/convert_m_file.m
+12
-12
没有找到文件。
rspower/data/convert_m_file.m
查看文件 @
94bfd925
function
convert_m_file
(
input_file
,
output_file
)
function
convert_m_file
(
input_file
,
output_file
)
% input_file:
输入.m文件路径(例如 'case14.m')
% input_file:
输入.m文件路径(例如 'case14.m')
% output_file
:输出.txt文件路径(例如 'case14_mems.txt')
% output_file
:输出.txt文件路径(例如 'case14_mems.txt')
%
将matpower矩阵格式转换为mems支持的脚本矩阵格式
%
将matpower矩阵格式转换为mems支持的脚本矩阵格式
%
可识别mpc的bus、gen、branch、gencost矩阵(第21行处可手动增删)
%
可识别mpc的bus、gen、branch、gencost矩阵(第21行处可手动增删)
%
读取输入文件
%
读取输入文件
run
(
input_file
);
run
(
input_file
);
mpc
=
ans
;
mpc
=
ans
;
%
打开输出文件
%
打开输出文件
fid
=
fopen
(
output_file
,
'w'
);
fid
=
fopen
(
output_file
,
'w'
);
if
fid
==
-
1
if
fid
==
-
1
error
(
'
无法打开文件
'
);
error
(
'
无法打开文件'
);
end
end
%
写入
baseMVA
%
写入b
aseMVA
fprintf
(
fid
,
'baseMVA = %d;\n\n'
,
mpc
.
baseMVA
);
fprintf
(
fid
,
'baseMVA = %d;\n\n'
,
mpc
.
baseMVA
);
%
固定读取的矩阵名称并遍历、转换
%
固定读取的矩阵名称并遍历、转换
matrix_names
=
{
'bus'
,
'gen'
,
'branch'
,
'gencost'
};
matrix_names
=
{
'bus'
,
'gen'
,
'branch'
,
'gencost'
};
for
i
=
1
:
length
(
matrix_names
)
for
i
=
1
:
length
(
matrix_names
)
matrix_name
=
matrix_names
{
i
};
matrix_name
=
matrix_names
{
i
};
...
@@ -33,11 +33,11 @@ function convert_m_file(input_file, output_file)
...
@@ -33,11 +33,11 @@ function convert_m_file(input_file, output_file)
end
end
fclose
(
fid
);
fclose
(
fid
);
disp
([
'
文件已转换并保存为
: '
,
output_file
]);
disp
([
'
文件已转换并保存为: '
,
output_file
]);
end
end
function
formatted_matrix
=
format_matrix
(
input_matrix
)
function
formatted_matrix
=
format_matrix
(
input_matrix
)
%
输入矩阵input_matrix,输出格式化后的
formatted_matrix
%
输入矩阵input_matrix,输出格式化后的format
ted_matrix
[
num_rows
,
~
]
=
size
(
input_matrix
);
[
num_rows
,
~
]
=
size
(
input_matrix
);
formatted_matrix
=
[];
formatted_matrix
=
[];
...
@@ -45,7 +45,7 @@ function formatted_matrix = format_matrix(input_matrix)
...
@@ -45,7 +45,7 @@ function formatted_matrix = format_matrix(input_matrix)
for
i
=
1
:
num_rows
for
i
=
1
:
num_rows
row
=
input_matrix
(
i
,
:);
row
=
input_matrix
(
i
,
:);
%
将该行的元素转换为逗号分隔的字符串
%
将该行的元素转换为逗号分隔的字符串
formatted_row
=
strjoin
(
arrayfun
(
@
(
x
)
num2str
(
x
),
row
,
'UniformOutput'
,
false
),
','
);
formatted_row
=
strjoin
(
arrayfun
(
@
(
x
)
num2str
(
x
),
row
,
'UniformOutput'
,
false
),
','
);
if
i
~=
num_rows
if
i
~=
num_rows
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论