Convert Matrix to Vector in Simulink

44 ビュー (過去 30 日間)
Fabian Gock
Fabian Gock 2017 年 7 月 31 日
コメント済み: Honglei Chen 2017 年 7 月 31 日
I want to convert a matrix like:
m= [t1 v1
t2 v2
t3 v3
t4 v4]
(where t are values representing the time and v are the actual values)
into a vector
v=[v1
v2
v3
v4]
attempts using the selector block failed, because I don't really know how to use it, and the documentation is not really clear to me.
I also tried using a Matlab code block.
function [voltage, current] = matrix2vector(u, i)
u(:,2)=[];
i(:,2)=[];
voltage = u;
current = i;
and
function [voltage, current] = matrix2vector(u, i)
voltage = u(:,2);
current = i(:,2);
But i get the error: Index expression out of bounds. Attempted to access element 2. The valid range is 1-1. More information
Function 'MATLAB Function' (#35.83.84), line 4, column 15: "2"
Thank you in advance -Fabian
  1 件のコメント
Fabian Gock
Fabian Gock 2017 年 7 月 31 日
I don't have the DSP System Toolbox. So I can't use the Variable Selector..

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

回答 (1 件)

Honglei Chen
Honglei Chen 2017 年 7 月 31 日
You should be able to use Selector to do it. In your dialog,
set Number of input dimensions to 2 set Index mode to one based set the first dimension as Select All set the second dimension as Index vector (dialog) and then enter 2
I've attached a snapshot for your reference. Does it address your issue?
  2 件のコメント
Fabian Gock
Fabian Gock 2017 年 7 月 31 日
編集済み: Fabian Gock 2017 年 7 月 31 日
Thank you for your quick answer. I tried your suggested way but I got the following error
Maybe it is important to know that the matrix i want to convert is imported from the Workspace using a From Workspace block.
Honglei Chen
Honglei Chen 2017 年 7 月 31 日
This means that you don't have a matrix. Rather you only have a column vector at the selector input. Maybe what you get is already the value itself? Unless you provide more info regarding how the original input is organized and how the from Workspace is configured, it's hard for others to guess what the issue might be.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by