How to store multiple arrays into a single one?

55 ビュー (過去 30 日間)
Mariana
Mariana 2020 年 5 月 3 日
コメント済み: Mariana 2020 年 5 月 3 日
array_1 = zeros(1,9);
array_2 = zeros(500,16);
With the increase in time I will be concatenating arrays one and two into array3. I tried it by doing this:
array_3 = [array_1,array2];
Since, they are not from the same size, they can´t be concatenated.
Any ideas on how can I save them?

採用された回答

Stephen23
Stephen23 2020 年 5 月 3 日
  3 件のコメント
Stephen23
Stephen23 2020 年 5 月 3 日
"Is it better to use an cell array or an structure?"
It depends entirely on what you are doing:
  • if your data have an inherent sequence, then use a container array which can be accessed using indices (e.g. cell array, non-scalar structure, table rows).
  • if your data are best identified by parameter names, then use a container array which lets you use names (e.g. structure, table columns).
Use the simplest data type that can reasonably hold your data, as this will simplify your code.
Mariana
Mariana 2020 年 5 月 3 日
How to initialize the cell array?
function y = (input,vector)
persistent count
persistent array_3
persistent array_2
persistent array_1
persistent Matrix
if isempty (array_3)
array_3 = cell(1000,2);
%array_3 = cell(repmat({zeros(1,9)}, 100, 1),repmat({zeros(1,9)}, 100, 2));
count = 0;
array_1 = zeros(1,9);
array_2 = zeros(500,16);
end
%Merge
Matrix(1:500,1:15)= data;
Matrix(1:500,16)= input;
%Look through the data
peak = find(Matrix(:,16)== 1);
val = length(peak);
if val > 5
Counter = Counter + 1;
array_3{Counter,1} = array_1;
array_3{Counter,2} = array_2;
end
y = array_3;
Error:
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:MATLAB Function | Category:Coder error
Cell arrays as top-level function outputs are not supported in MATLAB Function Block. Output 'Output' is a cell array.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by