- The number of columns "u" comes from an input of the MATLAB Function block, so the data involved IS variable size.
- The MATLAB Function block is executed once at every simulation step. Are you sure this is what you want?
- A better approach is to process this randomness as initialization and then input the processed data into Simulink.
Select Random columns from a matrix as a signal in Simulink
2 ビュー (過去 30 日間)
古いコメントを表示
I have a matrix 360x9 in a from workspace block. By specifying a constant block with a value n, I would like to output n columns randomly selected from the data as an output and plot them on a scope. I have tried utilizing a MATLAB function block and using the following code
function y = fcn(u, data)
ncol=u
s=randi(size(data,2),1,ncol);
y=data(:,s)
end
This logic works in matlab alone, however when implemented into a MATLAB function block I recieve an error stating that y is inferred as a variable-size matrix and must be defined in terms of non-tunable parameters or specify variable size. If I specify variable size in the model explorer, the output signal has a nondiscrete sample time, and it must be discrete. Any help would be greatly appreciated. Thanks.
0 件のコメント
回答 (1 件)
Fangjun Jiang
2022 年 1 月 18 日
参考
カテゴリ
Help Center および File Exchange で Sources についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!