ALIST文件的读取

matlab实现

function [H,q,n,m,dv_max,dc_max,dv,dc,VN_contact,CN_contact]=alist_process(file_name)
% This function is designed to reconstruct a sparse matrix from the row and column information specified in a given alist file.

%% input variable
% alist file name : file_name

%% output variable
% H : sparse matrix

%% 
fid = fopen(file_name); 
n = fscanf(fid,'%d',1); 
m = fscanf(fid,'%d',1);
q = fscanf(fid,'%d',1);  

dv_max=fscanf(fid,'%d',1);  
dc_max=fscanf(fid,'%d',1);  

dv=zeros(1,n);
for i=1:n
    dv(i)=fscanf(fid,'%d',1); 
end

dc=zeros(1,m);
for i=1:m
    dc(i)=fscanf(fid,'%d',1); 
end

%% contact information extract
VN_contact=fscanf(fid,'%d',[dv_max*2 n]);
CN_contact=fscanf(fid,'%d',[dc_max*2 m]);

%% reconstruct the sparse matrix H (use the VN contact information)
H=zeros(m,n);
for i=1:n
    for j=1:dv(i)
        H(VN_contact(2*j-1,i),i)=VN_contact(2*j,i);
    end
end

%% reconstruct the sparse matrix H (use the CN contact information)
% H=zeros(m,n);
% for i=1:m
%     for j=1:dc(i)
%         H(i,CN_contact(2*j-1,i))=CN_contact(2*j,i);
%     end
% end

end

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值