Unexpected MATLAB operator ':' In Simulink MATLAB Function Block

I am building a Simulink block diagram that uses a MATLAB Function block. I've run an exact copy of the function in MATLAB, so I know all the syntax and structure (loops and if statements & paired ends, brackets) is correct. However, when I try to build the Simulink model I get the following error:
SimulinkError.PNG
The line in question is shown below and is intended to find the number of unique values in the first column of 'deck'.
nAlt = length(unique(deck(:,1)));
Again I know it works when I run it in MATLAB, so I am assuming it is a problem with Simulink's C coder. I am having a similar index-related error on a later line: SimulinkError.PNG
Machs = sort([deck(1,2),Mach,deck(end,2)]);
Is there a way to get around this sort of error? I would really prefer not to mess around with different ways to do these operations, since I feel like the colon and end operators are pretty basic MATLAB syntax and would surely be supported for C code generation. Please let me know if you come up with a solution or need to see the full code.

3 件のコメント

Walter Roberson
Walter Roberson 2019 年 7 月 8 日
Is it possible that there is some ambiguity over whether deck is a variable or function at that point? For example is deck loaded by a load() that has no output variable?
load matrix_that_includes_deck
Nathan Daniel
Nathan Daniel 2019 年 7 月 9 日
編集済み: Nathan Daniel 2019 年 7 月 9 日
The lines which generate deck are:
input = fopen('some_text_file','r');
deck = textscan(input,'%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f','HeaderLines',1);
fclose(input);
deck = cell2mat(deck);
From this I believe deck should always be a matrix variable.
Unless somehow that second line is fixing it to be a cell array in a way that is not a problem in Matlab but is a problem in simulink?
Walter Roberson
Walter Roberson 2019 年 7 月 9 日
In Simulink it can be important not to change data type of a variable.
input = fopen('some_text_file','r');
deckcell = textscan(input,'%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f','HeaderLines',1, 'collectoutput', 1);
fclose(input);
deck = deckcell{1};
There is a possibility that you might first have to use coder.varsize to define deck as 1 x 17 (with the 1 signalling that the actual dimension is variable.)

サインインしてコメントする。

回答 (1 件)

akanksha srivastav
akanksha srivastav 2023 年 9 月 6 日

0 投票

I also faced same error in simulink-
received_signal_1=[zeros(round(target_delay*Fs),numAntennas);repmat(ref_signal(:),1,numAntennas)];
for this matlab_line it shows unexpected error.

質問済み:

2019 年 7 月 8 日

回答済み:

2023 年 9 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by