gpt4 book ai didi

octave - 在 GNU Octave 中识别变量类型

转载 作者:行者123 更新时间:2023-12-04 10:44:09 26 4
gpt4 key购买 nike

在练习 Octave 时,我创建了一个名为 my_name = ["Andrew"] 的变量。在要求 Octave 解释它是否是一个字符串时,它输出了一个“0”。再次使用 typeinfo(my_name) 时我收到了 ans = string .为什么我会得到这种输出?

octave:47> my_name = ["Andrew"]

my_name = Andrew

octave:48> isstring(my_name)

ans = 0

octave:49> typeinfo(my_name)

ans = string

最佳答案

根据 the documentation (强调我的):

isstring (s)

Return true if s is a string array.

A string array is a data type that stores strings (row vectors of characters) at each element in the array. It is distinct from character arrays which are N-dimensional arrays where each element is a single 1x1 character. It is also distinct from cell arrays of strings which store strings at each element, but use cell indexing ‘{}’ to access elements rather than string arrays which use ordinary array indexing ‘()’.

Programming Note: Octave does not yet implement string arrays so this function will always return false.


即, isstring将永远返回 false (或 0 ),无论输入是什么。
您应该使用 ischar确定输入是否为字符数组(==字符串)。

关于octave - 在 GNU Octave 中识别变量类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59793505/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com