从单元阵列中的序列生成倒数矩阵(Matlab)(Generate reciprocal matrices from sequences in the cell array ( Matlab ))
我在一个单元格数组中有3个序列:
S= {'ABC','ACB','AB'} S{1}='ABC' means A<B<C and have the weights : A:3, B:2, C:1 S{2}='ACB' means A<C<B and have the weights : A:3, C:2, B:1 S{3}='AB' means A<B and have the weights : A:3, B:2
我想将Input_cell中的每个字符串转换为矩阵M [i,j],它必须满足这些条件:
M[i,i] =1 M[i,j] = 1/M[j,i] If S{1}(i)<S{1}(j) then M[i,j]=weight(S{1}(i))/weight(S{1}(j))
例如:在S {1} ='ABC'中,权重为A:3,B:2,C:1
If A<B then M[A,B]=3/2 and M[B,A]=2/3 If B<C then M[B,C]=2/1 and M[C,B]=1/2 ....etc
所以S {1}的预期矩阵是:
A B C A [1 3/2 3 B 2/3 1 2 C 1/3 1/2 1]
在S {2} ='ACB'中,ACB的权重将是A:3,C:2,B:1。 所以S {2}的预期矩阵是:
A B C A [1 3 3/2 B 1/3 1 1/2 C 2/3 2 1]
在S {3} ='AB'中,AB的权重将是A:3,B:2,C:未知。 如果存在未知值,我们将在矩阵中放置1。 例如M [A,C] = M [C,A] = M [B,C] = M [C,B] = 1。 因此,S {3}的预期矩阵将是:ABC A [1 3/2 1 B 2/3 1 1 C 1 1 1]如何输入字符串的单元格数组并将其转换为矩阵,如上所述?
I have 3 sequences in a cell-array :
S= {'ABC','ACB','AB'} S{1}='ABC' means A<B<C and have the weights : A:3, B:2, C:1 S{2}='ACB' means A<C<B and have the weights : A:3, C:2, B:1 S{3}='AB' means A<B and have the weights : A:3, B:2
I want to convert each of the strings in the Input_cell into a matrix M[i,j] which has to satisfy those conditions :
M[i,i] =1 M[i,j] = 1/M[j,i] If S{1}(i)<S{1}(j) then M[i,j]=weight(S{1}(i))/weight(S{1}(j))
For example: In S{1}= 'ABC' , and weights will be A:3, B:2, C:1
If A<B then M[A,B]=3/2 and M[B,A]=2/3 If B<C then M[B,C]=2/1 and M[C,B]=1/2 ....etc
So the expected matrix for S{1} would be:
A B C A [1 3/2 3 B 2/3 1 2 C 1/3 1/2 1]
In S{2}='ACB', the weights of ACB will be A:3, C:2, B:1. So the expected matrix of S{2} would be:
A B C A [1 3 3/2 B 1/3 1 1/2 C 2/3 2 1]
In S{3}='AB', the weights of AB will be A:3, B:2, C:unknown. If there is an unknown value, we will put 1 in the matrix. Such as M[A,C]=M[C,A]=M[B,C]=M[C,B]=1. So the expected matrix of S{3} would be: A B C A [1 3/2 1 B 2/3 1 1 C 1 1 1] How can I input the cell array of strings and convert them into matrices as above ?
原文:https://stackoverflow.com/questions/42500230
最满意答案
我只想做一个
find
这个find /hw/ -type f -print -exec cat {} \;
I would simply do a
find
to achieve thisfind /hw/ -type f -print -exec cat {} \;
相关问答
更多-
你需要熟悉“find”命令。 它是标准的Unix,用于遍历整个目录树。 试试find . 你会开始明白这个想法。 接下来试试吧find . -name \*.txt find . -name \*.txt 。 越来越近 :-)。 最后: find . -name \*.txt -exec ./prog.bash {} document Document \; You need to get familiar with the "find" command. It's standard Unix, for ...
-
使用.htaccess并不是实现这一目的的最佳方式 - 为了让您获得正确的目录,Wordpress定义了一系列函数。 它的设计适用于如下情况:Wordpress文件夹的结尾可能非常不同! 该函数将始终返回站点URL: home_url() ,例如: http://example.com/wordpress : http://example.com/wordpress 所以你可以像这样引用你的图片: ...
-
迭代的序列应该是"$directory"/*/ 。 for x in "$directory"/*/; do (cd "$x" files=(*) printf '%s\n' "${files[@]}" > filesNames.txt ) done The sequence to iterate over should be "$directory"/*/. for x in "$directory"/*/; do (cd "$x" files=(*) printf ...
-
Unix Shell命令将当前目录中的所有文件复制到子目录(Unix Shell command to copy all files inside current directory to subdirectory)[2022-04-25]
要复制所有“ 文件 ”,您需要排除其他子目录的副本。 你可以用短循环和复合命令来做到这一点,例如 for i in *; do [ -f "$i" ] && cp -a "$i" directoryname; done 有几种方法可以做到这一点。 如果这给你带来任何麻烦,请告诉我。 因为你是shell编程的新手,所以复合命令只是两个与( && )相关的命令(或更多)(如果第一个成功则执行第二个)和|| (这意味着只有在第一次失败时才执行第二次)。 如上所述,循环只执行以下操作: for i in *; d ... -
试试..\appicon.ico来一级。 根据文件夹嵌套添加尽可能多的内容 try ..\appicon.ico to come up by one level. add as many as u need depending on the folder nesting
-
所以我找到了一种更简单的方法。 int main() { system("chdir userFiles && dir /b * > fileList.txt"); } 我使用&&运算符将多个命令串连接在一起。 由于我只使用system()函数,因为所有这些命令都将成为同一进程的一部分。 So I worked out an easier way of doing this. int main() { system("chdir userFiles && dir /b * > fileList.txt") ...
-
我只想做一个find这个 find /hw/ -type f -print -exec cat {} \; I would simply do a find to achieve this find /hw/ -type f -print -exec cat {} \;
-
使用包含空格的单词(包括文件名)几乎不可能。 要清楚,make完全忽略所有类型的引号字符(double,single,back)。 在某些特定情况下,您可以使用技巧来使其工作。 但是,您没有向我们提供有关您实际行动的信息; 您将展示如何分配变量FILFILES和FILTER但不显示如何使用它们。 如果这些变量仅用于配方中,那么您通常可以使其工作。 如果您将它们作为先决条件使用,那么即使不是不可能,也将非常困难。 It's all but impossible to use words (including ...
-
正如@Mitch Wheat建议的那样,有一个选项SearchOption.AllDirectories 。 但是,请注意,当它命中无法访问的文件夹时,可能会导致UnauthorizedAccessException。 因此,对我来说最好的解决方案始终是使用递归函数,可以忽略无法访问的文件夹。 对于递归解决方案,请参阅StackOverflow或文件夹递归时 拒绝Directory.GetFiles()时忽略文件夹/文件 As @Mitch Wheat suggested, there is the opt ...
-
在File :: Find的文档中说: 除非指定了no_chdir,否则在调用函数时,你是$ File :: Find :: dir的chdir()。 请注意,当更改到目录实际上,根目录(/)是一个有点特殊的情况,因为$ File :: Find :: dir,'/'和$ _的串联不等于$ File :: Find ::名称。 所以你实际上已经在~/sub了。 只使用文件名,即$_ 。 您不需要覆盖它。 删除行: $_ = $File::Find::name; In the documentation ...