Invalid index into an array of size {6, 22} with 132.

5 次查看(过去 30 天)
I have implement a custom component with some parameters. One of them is a
DxMap = [0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98;
0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98;
0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98;
0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98;
0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98;
0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98];
And some inputs:
inputs
zTerrain = { [0, 0, 0], '1'}; % zTerrain : left
wkette = { 0, 'rad/s'}; % wkette:left
% [soilType; soilState; frAdd]
soilInfo = {[1; 1; 0], '1'}; % soilInfo : left
end
My equation section looks like:
equations
z.der == HLZ.v;
let
soilType = soilInfo(1);
soilState = soilInfo(2);
Dx = DxMap(soilState, soilType);
...
in
...
end
end
The Dx = DxMap(soilState, soilType); assigment gives me the error message: Invalid index into an array of size {6, 22} with 132.
Working with constant indices for soilState and soilType is working, but this is not what I want to do. They have to be input values.
Can anyone tell me, what's going wrong here?
  1 个评论
Walter Roberson
Walter Roberson 2024-8-19
I wonder if inside SimScape, indexes start from 0? If so then you might need
soilType = soilInfo(1) - 1;
soilState = soilInfo(2) - 1;

请先登录,再进行评论。

采纳的回答

Sai Sri Pathuri
Sai Sri Pathuri 2020-7-9
This might be because you are assigning first element of soilInfo (which is a matrix) to soiltype and second element (which is a character) to soliState.
% [soilType; soilState; frAdd]
I assume from this comment that soilType and soilState are first and second elements of the matrix [1;1;0] in soilInfo. You may define soilType and soilState as
soilType = soilInfo{1}(1);
soilState = soilInfo{1}(2);
Also use soilType and soilState values such that they are less than 6 and 22 respectively for DxMap matrix defined above
  2 个评论
Marco Lehmann
Marco Lehmann 2020-7-9
I'm now using a simple tablelookup
Dx = tablelookup(soilStates, soilTypes, DxMap, soilType, soilState, interpolation=linear, extrapolation=nearest) in my euatiions block instead of Dx = DxMap(soilState, soilType).
This is working well.
Felix
Felix 2024-8-19
@Sai Sri Pathuri This answer is wrong. This is not Matlab, but Simscape language. soilInfo is not a cell array. The '1' just indicates that the input is unit-less.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Composite Components 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by