【Simulink】报错:Size mismatch (size [2 x 1] ~= size [1 x 1]). The size to the left is the size of the l

简介: 【Simulink】报错:Size mismatch (size [2 x 1] ~= size [1 x 1]). The size to the left is the size of the l

版本:Matlab2019b

背景信息:

我在 Simulink 里面的 stateflow 里面,写了一个 Matlab Function,参照了实验室往届师兄的代码,同样都是单输入单输出函数,但是用的变量大小不一样。

报错信息:

直接套用函数果然出现了问题。

Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
Component:Stateflow | Category:Coder error
Size mismatch (size [2 x 1] ~= size [1 x 1]).
The size to the left is the size of the left-hand side of the assignment.
Function 'thd_cal' (#135.1133.1141), line 47, column 1:
"thd_temp"
Launch diagnostic report.
Component:Stateflow | Category:Coder error
Error while generating code for chart Chart.
Component:Stateflow | Category:Coder error
Error while generating code for chart Chart.
Component:Simulink | Category:Model error
Error occurred in 'MPC_SPI6/Chart'.
Component:Simulink | Category:Model error

看了网上的解决方法,比如修改变量名,还是没能解决。

解决方法:

Size mismatch (size [2 x 1] ~= size [1 x 1]).
The size to the left is the size of the left-hand side of the assignment.
Function 'thd_cal' (#135.1133.1141), line 47, column 1:
"thd_temp"

从报错信息可以看出,变量 thd_temp 有问题,原本是 size [2 x 1] ,但运行结果是 size [1 x 1] .

根据报错信息提示,修改变量大小。

点击 MODELING -> Model Explorer

可以看到各种模块变量的信息,在 Stateflow “Chart” 下面除了 State,还有自己写的 Matlab Function “thd_cal”

点击"thd_cal",修改里面变量大小

根据报错信息提示,把 [2, 1] 改成 1 即可。

这时候再运行,就没有 Size 报错了。

相关文章
|
7月前
GEE错误——Layer error: Image.connectedPixelCount: Segment size calculation on floating point bands is n
GEE错误——Layer error: Image.connectedPixelCount: Segment size calculation on floating point bands is n
81 0
RuntimeError: Given groups=1, weight of size 64 128 1 7, expected input[16,
RuntimeError: Given groups=1, weight of size 64 128 1 7, expected input[16,
2982 0
|
7月前
|
关系型数据库 MySQL
MySQL【问题 02】报错 1709 - Index column size too large. The maximum column size is 767 bytes. 可能是最简单的方法
MySQL【问题 02】报错 1709 - Index column size too large. The maximum column size is 767 bytes. 可能是最简单的方法
236 0
|
索引
Result window is too large, from + size must be less than or equal to: [10000]
Result window is too large, from + size must be less than or equal to: [10000]
240 0
The size of tensor a (4) must match the size of tensor b (3) at non-singletonThe size of
The size of tensor a (4) must match the size of tensor b (3) at non-singletonThe size of
1113 0
Expected more than 1 value per channel when training, got input size torch.Size
因为模型中用了batchnomolization,训练中用batch训练的时候当前batch恰好只含一个sample,而由于BatchNorm操作需要多于一个数据计算平均值,因此造成该错误。
935 0
|
JSON 数据格式
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
531 0
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
成功解决lightgbm.basic.LightGBMError: Parameter max_depth should be of type int, got “0.02“
成功解决lightgbm.basic.LightGBMError: Parameter max_depth should be of type int, got “0.02“