Cell array and num2str comparison

조회 수: 2 (최근 30일)
Nadav
Nadav 2022년 9월 11일
댓글: Nadav 2022년 9월 12일
Hi,
I want to know the diiference in the attacehd image, ass well i would like to know how to convert [] to '' the strcamp will work well.
groupName = [11,12];
a = num2cell(groupName)
c = {'42', '12'}
rows = strcmp(a,c)
thanks,
Nadav

채택된 답변

Jan
Jan 2022년 9월 11일
The variable a is a cell array containing 2 scalar numbers, while b contains 2 CHAR vectors.
a = {42, 12}
a = 1×2 cell array
{[42]} {[12]}
c = {'42', '12'}
c = 1×2 cell array
{'42'} {'12'}
The square brackets are shown in the command window only an converting them to quotes is not meaningful.
There are many ways to compare the two cell arrays:
a1 = [a{:}];
c1 = str2double(c)
c1 = 1×2
42 12
a1 == c1
ans = 1×2 logical array
1 1
or
a2 = sprintfc('%d', [a{:}])
a2 = 1×2 cell array
{'42'} {'12'}
strcmp(a2, c)
ans = 1×2 logical array
1 1

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 9월 11일

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by