Filter löschen
Filter löschen

syntax cellstr Error when using double as input argument

3 Ansichten (letzte 30 Tage)
Hi there,
Octave does work correctly .
n = 4;
class(n)
ans = double
cellstr(n)
ans =
{
[1,1] =
}
I run the following code, I get the error shown below. At the same time Octave does work correctly .
Error using cellstr (line 49)
Conversion to cellstr from double is not possible.
n = 4;
class(n)
ans = 'double'
cellstr(n)
Error using cellstr
Conversion to cellstr from double is not possible.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 14 Jul. 2022
It is a bug in Octave. Octave cellstr documents that its input must be strmat, a string matrix and currently char arrays are the only implemented string matrix. But Octave cellstr is failing to check the input data type.
  2 Kommentare
Life is Wonderful
Life is Wonderful am 15 Jul. 2022
@Walter Roberson, I agree with your explanation, but I expect Matlab to do more implementation for numbers ( support all categorical ) , since they're checking data type.
Thank you for your time and efforts, @Fangjun Jiang and @Walter Roberson.
Walter Roberson
Walter Roberson am 15 Jul. 2022
MATLAB has always been clear that the inputs must be character (vector or 2d), or cell array of character vectors, or string() array. It has no reason to support double() or logical() or categorical() or any of the integer data types, and doing so would introduce questions such as whether 50 decimal should result in {'2'} or {'50'} . Those questions are best handled by the user converting to char or string() before calling cellstr.
Do not expect Octave and MATLAB to be completely compatible. For example MATLAB uses UTF-16 internally (nominally) so char(256) is U+0100 but Octave uses 8 bit characters and a lot of character processing would have to be done to support 16 bit characters.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Fangjun Jiang
Fangjun Jiang am 14 Jul. 2022
There is no point comparing two functions (with the same name) in two software and demanding one behaves the same way as the other. See "doc cellstr" in MATLAB for its syntax.
What do you expect cellstr(2) in MATLAB? Similar to zeros(2) or ones(2), or like below?
cellstr(["","";"",""])
ans = 2×2 cell array
{0×0 char} {0×0 char} {0×0 char} {0×0 char}
In fact, what is the output of cellstr(4) in Octave? It was not clear for me to see from your post.
  2 Kommentare
Life is Wonderful
Life is Wonderful am 14 Jul. 2022
Bearbeitet: Life is Wonderful am 14 Jul. 2022
I do not understand why there is a difference between the built-in functions for octave.
cellstr(4)
ans =
{
[1,1] =
}
Additionally, although this is a possibility in my opinion, it is also inaccurate.
length = cellstr(char(4))
length = 1×1 cell array
{''}
length = cellstr(char("1,1"))
length = 1×1 cell array
{'1,1'}
what advice would you give in this situation? who is in this room? !!
Walter Roberson
Walter Roberson am 14 Jul. 2022
MATLAB is created by programming professionals who have full access to existing matlab source code, and have decades of institutional coding "best practices" and testing frameworks.
Octave is developed by volunteers in their spare time. They are, if I understand correctly, legally not permitted to examine whatever matlab source code might be visible, as that could be considered reverse engineering under the terms of the Mathworks licenses. They have to work based strictly on the published documentation, as there is legal precedent that published APIs can be duplicated in a "clean-room" development system. And the volunteers sometimes simply overlook matters such as proper type checking.

Melden Sie sich an, um zu kommentieren.

Tags

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by