How to check repeated multiple cell array data for one decimal value?
古いコメントを表示
Checking the first two set of data in individula cell of 'A' with its 1st decimal value only but could not implement the logical statement with the converted data.


load("A.mat");
count = 0;
for i= 1:3
%B{1,i} = A{1,i}';
C{1,i} = sprintf('%10.1f',A{1,i}); % converted to the values
B{1,i} = reshape(sscanf(sprintf('%10.1f*', A{1,i}),'%f*'),[],1); % converted into single column (1x3)
% if all((B(1,1) == B(i,1)) && (B(2,1)==B(1,i)) % invalid
% count = count+1;
% else
% fprintf("does not matched with any data")
% end
end
6 件のコメント
Do you want compare the first digits of the values to the first digit of the 1st element in the row?
A=load("A.mat").A;
B=A{1,1}
base=10.^floor(log10(abs(B)));
y=fix(B./base)
all(diff(y,1,2)==0,'all')
Suman
2023 年 1 月 15 日
Dyuman Joshi
2023 年 1 月 15 日
So you want to see, if there is the values (rounded to 1 point after decimal) are repeating or not, in their respective row?
And what if they are repeating? What would you want to do afterwards? Find the indices where the repeatition occurs?
Suman
2023 年 1 月 15 日
A=load("A.mat").A
for idx=1:numel(A)
%rounding upto 1 point after decimal
B=round(A{idx},1);
%checking if the line is repeated or not
fprintf('Checking for repetition in row1 of A{1,%d}',idx)
row1=any(abs(B(1,2:end)-B(1,1))<1e-1,2)
fprintf('Checking for repetition in row2 of A{1,%d}',idx)
row2=any(abs(B(2,2:end)-B(2,1))<1e-1,2)
%use find() to obtain the indices where the repetition occurs
end
Suman
2023 年 1 月 16 日
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!