Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
 
 
主题工具 显示模式
旧 2019-12-10, 20:30   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 计算数组元素持久性算法

我有一个大型阵列15x15x2200。这仅仅是15x15稀疏矩阵的集合,描述了15个节点之间的链接以及它们在2200个时间单位内的变化情况。我需要计算每个链接持续多少时间。我的意思是,假设A [4,11]在时间单位5之前为0,在时间单位20之前保持为1,然后变为0,然后又从42变为46,再次变为1,我希望将此信息数组放入一个分别存储这些长度的数组,例如LEN = {... 15,4,....}

我正在尝试在matlab中执行此操作,然后生成直方图。做这个的最好方式是什么?



回答:

让我们尝试不使用循环。

%# random adjacency matrix array = randi([0 1], [15 15 2200]); %# get the size of the array [n1,n2,n3] = size(array); %# reshape it so that it becomes n3 by n1*n2 array2d = reshape(array,[],n3)'; %# make sure that every run has a beginning and an end by padding 0's array2d = [zeros(1,n1*n2);array2d;zeros(1,n1*n2)]; %# take the difference. +1 indicates a start, -1 indicates an end arrayDiff = diff(array2d,1,1); [startIdx,startCol] = find(arrayDiff==1); [endIdx,endCol] = find(arrayDiff==-1); %# since every sequence has a start and an end, and since find searches down the columns %# every start is matched with the corresponding end. Simply take the difference persistence = endIdx-startIdx; %# you may have to add 1, if 42 to 46 is 5, not 4 %# plot a histogram - make sure you play with the number of bins a bit nBins = 20; figure,hist(persistence,nBins) 编辑:

要查看轨道持续性的另一种视觉表示形式,请致电

figure,imshow(array2d) 无论您有多少个链接序列,它都将显示白色条纹,并且将向您显示总体图案。



更多&回答...
poster 当前离线   回复时引用此帖
 


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 14:21


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.