Program Examples:Octave interface/zh-hans
语言: | English • 中文(简体) |
---|
读取softMC记录文件的Octave函数的示例。 (Octave是一个与Matlab类似语法的开源软件)
function [rec, vars] = MCplot(filepath)
fid = fopen(filepath,'r'); % open file and save its id to fid
n = fread(fid,1,'int32'); % n-> raw number of columns
n = mod(n,16); % n -> fix the number of columns
m = fread(fid,1,'int32'); % m -> number of rows
gap = fread(fid,1,'int32');
vlen= fread(fid,1,'int32');
vars = fgets(fid,vlen); % vars -> string stating the recorded variables
rec = zeros(m,n);
for i = 1:m
for j = 1:n
rec(i,j) = fread(fid,1,'double');
end
end
fclose(fid);
end
返回的参数是“rec”和“vars”,“vars”是一个表示记录变量的字符串,“rec”是矩阵中排序的这些变量的数据,使得var_1 - > rec(:,1),var_2 - > rec(,,2)... var_n - > rec(:,n)。
绘制2D数据的示例:
[rec, vars] = MCplot('C:\SoftMC\Projects\test.rec')
plot(rec(:,1),rec(:,2));
将3D数据绘制为曲线的示例:
[rec, vars] = MCplot('C:\SoftMC\Projects\test.rec')
plot3(rec(:,1),rec(:,2),rec(:,3));