MATLAB Answers

0

Variable into block "from workplace"

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 !

  0 Comments

Sign in to comment.

5 Answers

Answer by Davide Ferraro on 15 Feb 2011
 Accepted Answer

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);

  0 Comments

Sign in to comment.


Answer by Kaustubha Govind on 15 Feb 2011

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.

  0 Comments

Sign in to comment.


Answer by Guillaume on 15 Feb 2011

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

  0 Comments

Sign in to comment.


Answer by Guillaume on 15 Feb 2011

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.

  0 Comments

Sign in to comment.


Answer by Guillaume on 15 Feb 2011

Thanks you !

  0 Comments

Sign in to comment.