gpt4 book ai didi

matlab - CLASS 函数必须从类构造函数中调用

转载 作者:行者123 更新时间:2023-12-02 21:37:24 26 4
gpt4 key购买 nike

我正在尝试查找结构体字段的类型。

我尝试对我认为是数组的内容调用 prod,但收到此错误:

??? Error using ==> prod
Dimension argument must be a positive integer scalar within indexing range.

所以我打印了有问题的对象并发现了这个:

K>> F.val

ans =

0.110000000000000 0.890000000000000


ans =

0.590000000000000 0.410000000000000 0.220000000000000 0.780000000000000


ans =

0.390000000000000 0.610000000000000 0.060000000000000 0.940000000000000

这与数组的输出不同,它是:

K>> [0.11 0.89 0.59 0.41 0.22 0.78 0.39 0.61 0.06 0.94]

ans =

Columns 1 through 4

0.110000000000000 0.890000000000000 0.590000000000000 0.410000000000000

Columns 5 through 8

0.220000000000000 0.780000000000000 0.390000000000000 0.610000000000000

Columns 9 through 10

0.060000000000000 0.940000000000000

当我在对象上调用 class 时,出现以下错误:

K>> class(F.val)
??? Error using ==> class
The CLASS function must be called from a class constructor.

如何找到F.val的类型?

最佳答案

F 很可能是一个结构数组。因此,调用 class(F.val) 就像调用 class(F(1).val, F(2).val, F(3).val),这与单输入元素语法不同。

使用class(F(1).val)获取F第一个元素的val的类。

顺便说一句,prod 的错误很可能具有类似的根源。 prod(F(1).val) 工作正常,但是,有两个输入时,第二个被假定为维度参数,并且需要是一个整数(可以是 不过,class double )。

关于matlab - CLASS 函数必须从类构造函数中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21077314/

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