How to check repeated multiple cell array data for one decimal value?

조회 수: 7 (최근 30일)
Suman
Suman 2023년 1월 14일
댓글: Suman 2023년 1월 16일
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
Dyuman Joshi
Dyuman Joshi 2023년 1월 15일
A=load("A.mat").A
A = 1×3 cell array
{2×766 double} {2×766 double} {2×995 double}
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
Checking for repetition in row1 of A{1,1}
row1 = logical
1
Checking for repetition in row2 of A{1,1}
row2 = logical
1
Checking for repetition in row1 of A{1,2}
row1 = logical
1
Checking for repetition in row2 of A{1,2}
row2 = logical
1
Checking for repetition in row1 of A{1,3}
row1 = logical
0
Checking for repetition in row2 of A{1,3}
row2 = logical
1
Suman
Suman 2023년 1월 16일
Thank you so much Dyuman.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by