필터 지우기
필터 지우기

compare char (and empty elements) present in two cells

조회 수: 1 (최근 30일)
Alberto Acri
Alberto Acri 2023년 7월 26일
편집: Bruno Luong 2023년 7월 26일
Hi! I need to compare char (and empty elements) present in two cells. I made this code which works but it gives me an 'error' when it compares two empty cell elements (position [3,1] in 'cell_1' and 'cell_2'). In this case it returns 0 (false), i.e. they are not identical. How can I solve it?
cell_1 = importdata("cell_1.mat");
cell_2 = importdata("cell_2.mat");
row = height(cell_1);
column = width(cell_1);
siz = [row,column];
matrix_check = cell(siz);
for X = 1:row
for Y = 1:column
A = cell_1{X,Y};
B = cell_2{X,Y};
% if A == B
%
% tf = logical(1);
%
% else
tf = strcmp(A,B); % returns 1 (true) if the two are identical and 0 (false) otherwise
% end
matrix_check{X,Y} = tf;
end
end
  댓글 수: 1
Bruno Luong
Bruno Luong 2023년 7월 26일
편집: Bruno Luong 2023년 7월 26일
matrix_check = cell(siz);
You seem to have a bad habit of abusing cell storage for no apparent reason.

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

채택된 답변

Bruno Luong
Bruno Luong 2023년 7월 26일
replace the problematic command with
tf = strcmp(char(A),char(B));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by