Why I knock into a error when I want to get data from my double?

R = [[1 0.9954 0.9994 0.9989];
[0.9954 1 0.9926 0.9923];
[0.9994 0.9926 1 0.9977] ;
[0.9989 0.9923 0.9977 1]];
% 一级偏相关系数
R_PC1 = [PC1(1,2,3) PC1(1,2,4) PC1(1,3,2) PC1(1,3,4) PC1(1,4,2) PC1(1,4,3)
PC1(2,3,1) PC1(2,3,4) PC1(2,4,1) PC1(2,4,3) PC1(3,4,1) PC1(3,4,2)];
Incorrect number or types of inputs or outputs for function R.

Error in solution>PC1 (line 12)
r = (R(a,b)-R(a,c)*R(b,c))/sqrt((1-R(a,c)^2)*(1-R(b,c)^2));
% 二级偏相关系数
R_PC2 = [PC2(1,2,3,4) PC2(1,3,2,4) PC2(1,4,2,3) PC2(2,3,1,4) PC2(2,4,1,3) PC2(3,4,1,2)];
% 计算一级偏相关系数
function[r] = PC1(a,b,c) % 在c不变的情况下,a和b之间的相关系数
r = (R(a,b)-R(a,c)*R(b,c))/sqrt((1-R(a,c)^2)*(1-R(b,c)^2));
end
function[r] = PC2(a,b,c,d) %在c,d不变的情况下,a和b之间的相关系数
r = (PC1(a,b,c)-PC1(a,d,c)*PC1(b,d,c))/sqrt((1-PC1(a,d,c)^2)*(1-PC1(b,d,c)^2));
end
This program knock into a error at line15 and it read'出错 coord>PC1 (第 15 行)'
检查对函数 'R' 的调用中是否存在不正确的参数数据类型或缺少参数。
It seems that MATLAB see the 'R' as a function rather than a Matrix

 Risposta accettata

In ‘PCI1’ you are referencing ‘R’ however you are not passing it to ‘PCI1’ as an argument.
Perhaps this —
R = [[1 0.9954 0.9994 0.9989];
[0.9954 1 0.9926 0.9923];
[0.9994 0.9926 1 0.9977] ;
[0.9989 0.9923 0.9977 1]];
% 一级偏相关系数
R_PC1 = [PC1(1,2,3,R) PC1(1,2,4,R) PC1(1,3,2,R) PC1(1,3,4,R) PC1(1,4,2,R) PC1(1,4,3,R)
PC1(2,3,1,R) PC1(2,3,4,R) PC1(2,4,1,R) PC1(2,4,3,R) PC1(3,4,1,R) PC1(3,4,2,R)]
R_PC1 = 2×6
0.8073 0.7217 0.9770 0.8801 0.9409 0.7661 -0.6638 0.3076 -0.4463 0.2409 -0.3698 0.8473
% 二级偏相关系数
R_PC2 = [PC2(1,2,3,4,R) PC2(1,3,2,4,R) PC2(1,4,2,3,R) PC2(2,3,1,4,R) PC2(2,4,1,3,R) PC2(3,4,1,2,R)]
R_PC2 = 1×6
0.9984 0.9992 0.9981 -0.9969 -0.9956 -0.9953
% 计算一级偏相关系数
function [r] = PC1(a,b,c,R) % 在c不变的情况下,a和b之间的相关系数
r = (R(a,b)-R(a,c)*R(b,c))/sqrt((1-R(a,c)^2)*(1-R(b,c)^2));
end
function [r] = PC2(a,b,c,d,R) %在c,d不变的情况下,a和b之间的相关系数
r = (PC1(a,b,c,R)-PC1(a,d,c,R)*PC1(b,d,c,R))/sqrt((1-PC1(a,d,c,R)^2)*(1-PC1(b,d,c,R)^2));
end
.

2 Commenti

Thank you for your advise
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Accedi per commentare.

Più risposte (0)

Categorie

Prodotti

Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by