transpose matrix and data arrangement in simulink

8 ビュー (過去 30 日間)
yana osman
yana osman 2012 年 5 月 26 日
回答済み: Tejas 2024 年 10 月 25 日 7:35
Hi all, I have two questions to ask.hope someone can help me.
1. I have (321X4) matrix in my workspace. I want to transpose this matrix to (4X321) matrix but when i add transpose block in my diagram, the result appear is (1X4x321). How to get 2 dimension result?
2. I have (321X4) matrix in my workspace and i name it simout. For the next step, 1want to arrange my data like this time 1 = [simout(1,1) ; simout(1,2) ; simout(1,3) ; simout(1,4)]; I have done this arrangement in emmbedded matlab function. but unfortunately simout(1,1) were read as (1:321,1) so the matrix result is (321X1) matrix not (1X1) matrix. How to solve this problem?
All these works were done in simulink anyway.Thank you all
  1 件のコメント
Junaid
Junaid 2023 年 4 月 20 日
Hi you got any solution I am getting the same probelm ?

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

回答 (1 件)

Tejas
Tejas 2024 年 10 月 25 日 7:35
Hello Yana,
To make sure that transposing a matrix does not add any extra dimensions, try this workaround:
  • Add a 'MATLAB Function' block.
  • Inside this block, perform the transpose of the matrix. This method ensures that no additional dimensions are introduced.
function y = fcn(u)
y = u';
end
The function 'simout(i,j)' will retrieve the element at the specified indexes. For more information, refer to this documentation: https://www.mathworks.com/help/matlab/math/array-indexing.html.
Do ensure that the elements at those indexes are 1x1 in dimension. Assuming all elements in 'simout' are 1x1, the 'MATLAB Function' block can be used to retrieve the data in the desired format, as demonstrated in the code snippet below:
function y = arrangeData(simout)
y = [simout(1,1); simout(1,2); simout(1,3); simout(1,4)];
end

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by