【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 报错了。

相关文章
|
2月前
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
31 0
|
4月前
|
关系型数据库 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. 可能是最简单的方法
53 0
|
8月前
|
索引
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]
65 0
|
8月前
YOLO V5出现RuntimeError: result type Float can‘t be cast to the desired output type long int解决方法
YOLO V5出现RuntimeError: result type Float can‘t be cast to the desired output type long int解决方法
504 0
|
11月前
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
653 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
428 0
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
malloc(): corrupted top size
malloc(): corrupted top size
596 0
|
程序员 算法框架/工具 Caffe
解决办法:error: 'size_t' does not name a type、unknown type name 'size_t'
解决办法:error: 'size_t' does not name a type、unknown type name 'size_t'
587 0
成功解决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“
成功解决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