ato*_*3ls 0 file-io matlab file
我有一个.m文件,其中包含一些带有一些矩阵的结构:
%mymatfile.m
function [mymatrix,anothermatrix] = mymatfile;
mymatrix = [
1 2 0.0010 0.0010 0.0000 2.0000 2.0000 2.0000 1 0 1
2 3 2.0014 0.0007 0.0000 0.5000 0.5000 0.5000 0 0 1
3 4 0.0301 0.0001 4.0000 0.5000 0.5000 0.5000 1.16 0 1
4 5 0.0791 0.0450 0.0000 0.5000 0.5000 0.5000 0 0 1
5 6 1.0482 0.0233 0.0000 0.5000 0.5000 0.5000 0 0 1
5 7 7.5130 0.0467 0.0000 0.5000 0.5000 0.5000 0* 0 1
7 8 9.0161 0.0008 0.0000 0.5000 0.5000 0.5000 0 0 1
7 9 0.9070 0.2310 0.0000 0.5000 0.5000 0.5000 0 0 1
];
anothermatrix = [
2 0 0 3 0 10 0
9 0 0 3 0 10 0
%];
Run Code Online (Sandbox Code Playgroud)
如何更改已加星标的值(mymatrix(3,9))并保存文件,同时保留其结构/格式?我需要从另一个matlab脚本执行更新.
你可以保存mymatrix文本文件中的条目mymatrix_text.
然后你让你的函数读取该文本文件,即
%mymatfile.m
[mymatrix,anothermatrix] = function get_my_matrices()
fid = fopen(mymatrix_text);
mymatrix = fscanf(fid, '%g ');
fclose(fid);
% anothermatrix = %% you can do the same above..
end
Run Code Online (Sandbox Code Playgroud)
现在,如果您需要修改矩阵,您应该只修改文本文件 - 这样更容易,不涉及更改.m文件.
(例如,您可以创建另一个函数来读取mymatrix_text和更改所需的值).
这种方法对我来说看起来更健壮.
| 归档时间: |
|
| 查看次数: |
252 次 |
| 最近记录: |