An error occurred when calculating the correlation coefficient using "reduce_data_points" for two sets of data. Thanks for all the corrections.
古いコメントを表示
When using "reduce_data_points" to calculate the correlation coefficient of two sets of data, "The index exceeds the number of array elements (147)."
Error reduce_data_points (line 63)
varargout{i} = data{i}(save);" such a mistake. Thank you for your correction.
%%%%%%%Import two curve data%%%%%%%%%%%%%%%
load m1.mat;
load zhengsanjiao.mat
X=m1(:,1);
Y=m1(:,2);
x=A(:,1);
y=A(:,2);
a=size(X);
b=size(x);
c=min(a,b);
d=c(:,1);
%%%%%%%%%reduce data points%%%%%%%%%%%%%%%
[x_new,X_new] = reduce_data_points(x,X,d);
index1 = find(X_new); % or 'first'
Y_new=Y(index1);
index2 = find(x_new); % or 'first'
y_new=y(index2);
r=corrcoef(y_new,Y_new);
1 件のコメント
Wesley
2022 年 3 月 10 日
編集済み: Walter Roberson
2022 年 3 月 10 日
回答 (1 件)
Walter Roberson
2022 年 3 月 10 日
[x_new,X_new] = reduce_data_points(x,X,d);
Your x and X are different sizes. The first parameter needs to be no longer than the second parameter.
The reduce_data_points function does not apply the save ratio (last parameter) independently to each input: it assumes that all parameters other than the last parameter are the same size.
6 件のコメント
Wesley
2022 年 3 月 10 日
Wesley
2022 年 3 月 10 日
Wesley
2022 年 3 月 10 日
Walter Roberson
2022 年 3 月 10 日
x_new = reduce_data_points(x,d);
X_new = reduce_data_points(X,d);
Wesley
2022 年 3 月 10 日
Walter Roberson
2022 年 3 月 10 日
That reduction code with not reduce the first input at all unless the number of requested points is at most 2/3 of the number of points in the first input -- and when it does reduce, it will get the number of output points wrong unless the request is for quite close to 1/N of the original (1/2, 1/3, and so on.)
The code seems to be written assuming that all of the inputs are have corresponding points selected. It is not intended for the case where the inputs are different sizes. It is intended more for the case of (x,y) or (x,y,z) pairs that are to be thinned down to corresponding locations.
If your x and your X are intended to hold corresponding values, then there is something quite wrong with your data. Your .mat file has about 857 entries for one of them, and about 147 entries for the other. If they are assumed to match 1:1 then that is not clear.
If, however, what you want to do is extract samples the same length, but more or less at random, from the two variables, then there are better ways of handling that.
x_new = x(round(linspace(1, numel(x), d)));
X_new = X(round(linspace(1, numel(X), d)));
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
