How to solve "Attempted to access index 12 of an array with smaller dimension sizes" problem?

2 views (last 30 days)
SyukriY
SyukriY on 11 Oct 2016
Commented: SyukriY on 13 Oct 2016
Hi. I get an error "Attempted to access index 12 of an array with smaller dimension sizes".
This error occurred when I change 'constant block' with 'from file block'.
In the constant block, I have a set of data like this...
[35.85
35.74
36.03
35.36
35.36
35.74
36.03
35.95
36.03
35.82
35.83
35.25
35.9
36.07
36.2
35.92
35.66
35.94
36.02
35.94
35.92
35.84
36.2
36.28
]
and in the from file block the data is just the same as the data above.
Here is my code in the MATLAB function block.
function Consistency = detection(x)
H = x;
S = std(H(12:24,:));
Consistency = S;
end
Please give your suggestion.
Thank you.
  4 Comments
SyukriY
SyukriY on 12 Oct 2016
Hi, Walter Roberson.
As you assume, the assert fails. But, I have 24rows in the file. What could be wronged?

Sign in to comment.

Accepted Answer

Preethi
Preethi on 12 Oct 2016
Hi,
Save the data in .mat as columns, use transpose at the start of function.
The file must contain a matrix of two or more rows. The first row must contain monotonically increasing time points. Other rows contain data points that correspond to the time point in that column. The matrix is expected to have this form.
<http://www-rohan.sdsu.edu/doc/matlab/toolbox/simulink/slref/fromfile.html>
  3 Comments

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 12 Oct 2016
When you use From Workspace to bring in a matrix (I have not tested From File as much):
Rows of the variable correspond to timepoints. Column 1 will be used for the corresponding time. For each timepoint, a row without the first column will be passed to the function, but the row will be passed as a column vector. For example, for a 25 x 30 matrix, since the first row is time, there are 25 x 29 remaining data, and each function call will be passed a column of 29 values, with the function being called multiple times.
If you are trying to do this at initialization time, a one-time calculation with all of the data in the matrix, with the output becoming more or less a parameter for the run, then I am not sure if that is possible, but I would not rule it out (I do not have the experience to say.)

Tags

Community Treasure Hunt

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

Start Hunting!