[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #51412] strcmp with multidimensional char arra
From: |
Nicholas Jankowski |
Subject: |
[Octave-bug-tracker] [bug #51412] strcmp with multidimensional char arrays |
Date: |
Tue, 13 Dec 2022 16:57:03 -0500 (EST) |
Follow-up Comment #10, bug #51412 (project octave):
just providing an update with octave 8.0.1 (hg id: 24bd675bceab) and matlab
2022b:
no change in the comment #0 response except the 2D case in Octave now gives a
warning:
"warning: multi-row character matrix converted to a string, only the first row
is used"
adding in the Matlab behavior with string arrays:
%1D array
>> a = string('abc')
a =
"abc"
>> strcmp(a,a)
ans =
logical
1
>> strcmp(a,{a})
ans =
logical
0
>> strcmp({a},{a})
ans =
logical
0
>> strcmp(a,{a,a})
ans =
1×2 logical array
0 0
>> strcmp({a},{a,a})
ans =
1×2 logical array
0 0
>> a = ["abc","def"]
a =
1×2 string array
"abc" "def"
>> strcmp(a,a)
ans =
1×2 logical array
1 1
>> strcmp(a,{a})
ans =
1×2 logical array
0 0
>> strcmp({a},{a})
ans =
logical
0
>> strcmp(a,{a,a})
ans =
1×2 logical array
0 0
>> strcmp({a},{a,a})
ans =
1×2 logical array
0 0
%2D array
>> a = ["abc","def"; "ghi", "jkl"]
a =
2×2 string array
"abc" "def"
"ghi" "jkl"
>> strcmp(a,a)
ans =
2×2 logical array
1 1
1 1
>> strcmp({a},{a})
ans =
logical
0
>> strcmp(a,{a,a})
Error using strcmp
Inputs must be the same size or either one can be a scalar.
>> strcmp({a},{a,a})
ans =
1×2 logical array
0 0
%3D array
>> a = cat(3,a,a)
2×2×2 string array
a(:,:,1) =
"abc" "def"
"ghi" "jkl"
a(:,:,2) =
"abc" "def"
"ghi" "jkl"
>> strcmp(a,a)
2×2×2 logical array
ans(:,:,1) =
1 1
1 1
ans(:,:,2) =
1 1
1 1
>> strcmp(a,{a})
2×2×2 logical array
ans(:,:,1) =
0 0
0 0
ans(:,:,2) =
0 0
0 0
>> strcmp({a},{a})
ans =
logical
0
>> strcmp(a,{a,a})
Error using strcmp
Inputs must be the same size or either one can be a scalar.
>> strcmp({a},{a,a})
ans =
1×2 logical array
0 0
also, mike's check in comment #5, in octave 8.0.1:
>> a = ['aaa'; 'bbb'];
>> string_value (a)
error: 'string_value' undefined near line 1, column 1
>> cellstr_value (a)
error: 'cellstr_value' undefined near line 1, column 1
so it seems those functions no longer exist in octave?
and Rik's comment #6 and comment #7 tests:
Matlab 2022b:
>> x = {['aa'; 'bb']; ['aa'; 'cc']}
x =
2×1 cell array
{2×2 char}
{2×2 char}
>> strcmp (x, 'aa')
ans =
2×1 logical array
0
0
>> strcmp (x, {'aa'})
ans =
2×1 logical array
0
0
>> strcmp (x, {'aa';'cc'})
ans =
2×1 logical array
0
0
>> strcmp (x, {['aa';'cc']})
ans =
2×1 logical array
0
1
>> x = {['ab']; ['cd'; 'ef']}
x =
2×1 cell array
{'ab' }
{2×2 char}
>> iscellstr (x)
ans =
logical
1
>> y = {['ab']; ['c'; 'e']}
y =
2×1 cell array
{'ab' }
{2×1 char}
>> iscellstr (y)
ans =
logical
1
and the same tests in Octave 8.0.1:
ﻳ誂>> x = {['aa'; 'bb']; ['aa'; 'cc']};
>> strcmp (x, 'aa')
warning: multi-row character matrix converted to a string, only the first row
is used
warning: multi-row character matrix converted to a string, only the first row
is used
ans =
1
1
>> strcmp (x, {'aa'})
ans =
1
1
>> strcmp (x, {'aa';'cc'})
ans =
1
0
>> strcmp (x, {['aa';'cc']})
warning: multi-row character matrix converted to a string, only the first row
is used
ans =
1
1
>> x = {['ab']; ['cd'; 'ef']}
x =
{
[1,1] = ab
[2,1] =
cd
ef
}
>> iscellstr (x)
ans = 1
>> y = {['ab']; ['c'; 'e']}
y =
{
[1,1] = ab
[2,1] =
c
e
}
>> iscellstr (y)
ans = 1
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?51412>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Octave-bug-tracker] [bug #51412] strcmp with multidimensional char arrays,
Nicholas Jankowski <=