Variable into block "from workplace"

1 回表示 (過去 30 日間)
Guillaume
Guillaume 2011 年 2 月 15 日
Hi,
I have one little question about block "from Worksplace". I want to put a variable data to a Embedded matlab function, and then to a Scope.
But, when I define my data like that (in the workplace) :
data = 1:10;
I have this error :
"Invalid external input specified. The input has 10 data columns while the sum of the port widths of all inports in the model is 1."
For example, I want my variable data change like that : data (time = 1) = 1, data (time = 2) = 2 etc.
How can I do this ?
Thanks !

採用された回答

Davide Ferraro
Davide Ferraro 2011 年 2 月 15 日
From Workspace block should have a first column representing time and then your data columns. This should work fine:
data = [(1:10)',(1:10)'];
or using REPMAT:
data = repmat((1:10)',1,2);

その他の回答 (4 件)

Kaustubha Govind
Kaustubha Govind 2011 年 2 月 15 日
1) Yes. Essentially, the data defined in Davide's answer looks like this:
data =
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
Where the first column is time and second column is data. So you can write:
data = [[1:10]',[1 5 4 2 5 6 7 2 -1 7]'];
Or any arbitrary data in the second column.
2) The documentation explains how to use enumerated types with Simulink
3) I'm not sure what you mean by "more than one data", but you should find more information at the documentation page for From Workspace.

Guillaume
Guillaume 2011 年 2 月 15 日
Okay, so if I do " data = [(1:10)',(1:10)']; " my data will be 1 for time = 1, and 2 for time = 2, etc ?

Guillaume
Guillaume 2011 年 2 月 15 日
Well well ! It's work ! But now, with the From Worksplace block, how can I do to do something like that :
data = 1 when time = 0 data = 5 when time = 2
Can I choose the value of data for each moment of time ?
Other question : can I change data to an enum ? And have more than one data in the same From Workplace block ?
Thanks a lot, and sorry, I new in Matlab.

Guillaume
Guillaume 2011 年 2 月 15 日
Thanks you !

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by