I have 2 uni-dimentional arrays in workspace, one (xarray) is to be used as the x-axis and the other (yarray) as the y-axis.
xarray =
1 2 3 4 5 6 7 8 9 10
yarray =
500 200 800 0 0 0 0 0 0 0
What I want to do in Simulink is to read these arrays from the workspace and generate a X-Y graph. I can easily do that from the Matlab command-line (figure; plot(xarray, yarray)), however, I want to do it from Simulink.
I’ve tried to read each array from workspace by using two “for workspace” blocks which I then connected to the corresponding inputs of a ‘X-Y graph’, however, the error I got was:
Error in port widths or dimensions. Output port 1 of
‘simulink_model/XY Graph/Mux’ is a one dimensional vector with 18
elements.
Any help will be much appreciated, thanks.
simulink can be a bit tricky when using external matrices.
So a couple of things:
1) matrices need to have there array as columns (fortunatly you can do the transpose operation in simulink itself)
2) you need the first column to represt time-entry of the array:
so in your case, for the first input you can use
[xarray; xarray]', and the second input, you can use [xarray; yarray]’ (provided, of course xarray doesn’t change)3) don’t forget to modify the scope preferences to see all the data (default maxes to [-1;1])