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

2 views (last 30 days)
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
Thank you.
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?

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.
SyukriY on 13 Oct 2016
Yeah, got it.
Thank you so much for your help.

### More Answers (1)

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.)
##### 1 CommentShowHide None
SyukriY on 13 Oct 2016
Thanks to you too...