I have 50 EXCEL files. In Sheet 2 of each EXCEL file, there are mainly two columns called WA and CI. The program below should take these two columns and check if there are repeated values. I have attached one of the typical Excel files on here. The file is indexed 2.xlsx. The program has a for-loop on external files. The strange thing is that MATLAB says that CI has a repeated value but, checking the file, there is no repetition. If I copy the column CI in MATLAB. I execute the command length(CI) == length(unique(CI)). Then the result is 1. There are no repetead values. This corresponds to the truth because there are no repeated values in CI. I do not understand where I am wrong in this small program and why the two outcomes are different.
path_to_folder = '~/Desktop/75_3/';
for i=1:50
file = strcat(num2str(i),'.xlsx');
path_to_file = strcat(path_to_folder,file);
subset = xlsread(path_to_file,'Sheet2');
CI = subset(:,2);
length(CI) == length(unique(CI))
end

4 件のコメント

Mario Malic
Mario Malic 2021 年 3 月 6 日
why the two outcomes are different? Which ones, CI and WA? Maybe they are unique for the first file, but not for the others?
Francesco Ciardiello
Francesco Ciardiello 2021 年 3 月 6 日
I have corrected the post. The problem is just with CI. Thanks.
dpb
dpb 2021 年 3 月 6 日
The problem is still in the post -- I don't know what you did, but clearly the attached file has a duplicated entry in the second column, whatever you name the variable isn't going to either make it appear or go away.
>> CI=d(:,2);
>> length(CI)==length(unique(CI))
ans =
logical
0
>>
Whether the values are in the original array or a copy in another variable does not change the symptoms...
Even running the same code doesn't make any differenc--
>> path_to_folder = '';
for i=2:2
file = strcat(num2str(i),'.xlsx');
path_to_file = strcat(path_to_folder,file);
subset = xlsread(path_to_file,'Sheet2');
CI = subset(:,2);
length(CI) == length(unique(CI))
end
ans =
logical
0
>>
Francesco Ciardiello
Francesco Ciardiello 2021 年 3 月 7 日
You are right. I have accepted your answer, The repeated value is in the column CI (not in WA). But this does not make any difference. I think I had a look at the wrong column. The duplicate exists, you are right.

サインインしてコメントする。

 採用された回答

dpb
dpb 2021 年 3 月 6 日

0 投票

Well, there is a duplicate in the 2nd column...
>> d=xlsread('x.xlsx','Sheet2');
>> arrayfun(@(i)numel(unique(d(:,i)))==numel(d(:,i)),[1:2])
ans =
1×2 logical array
1 0
>>
> sd=sort(d(:,2));
>> find(diff(sd)==0)
ans =
71
>> sd(70:72)
ans =
0.759021496168829
0.765957446808511
0.765957446808511
>> [u,iu]=unique(d(:,2));
>> whos u
Name Size Bytes Class Attributes
u 74x1 592 double
>>

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Import from MATLAB についてさらに検索

製品

リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by