How to solve "Attempted to access index 12 of an array with smaller dimension sizes" problem?
2 views (last 30 days)
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...
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;
Please give your suggestion.
Preethi on 12 Oct 2016
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.
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.)