How to split data in reference to certain values from one column and organise into a cell array?- The logical indices in position 1 contain a true value outside of the array bounds. ERROR

2 visualizaciones (últimos 30 días)
I have a large data selection of 1037803 points for each test and 3 repeats. The data has 12 columns that indicate various different parameters. Column 6 indicates the speed of which the test ran. In total there was 100 different speeds. The first speed is 31.4159261390256 and then it increases by 31.4159 each time up to the last speed of 3141.59. Therefore, i want to split the data into a cell array that includes 100 rows, one for each speed with the data for each test next to it.
I have used this;
for n= 0:100 % 100 different speeds
ans = n;
indexes=((New_Data{1,1}(:,6)> (31+31.4159*n)& (New_Data{1,1}(:,6)<(32.4159+31.4159*n))) ) ; %values are not completly fixed and change by some degree
speeds{n+1,1} = num2str(31+31.4159*n); %first column = the speed values
speeds{n+1,2} = New_Data{:,1}(indexes,:); %test 1
speeds{n+1,3} = New_Data{:,2}(indexes,:); %test 2
speeds{n+1,4} = New_Data{:,3}(indexes,:); %test 3
end
This works well untill New Data {:,3} for the last speed, where it appears blank (figire 1) . I have checked my data and the data is same length and has the final speed so the original data is defo not the issue (figure 2).
I keep getting the following error.
The logical indices in position 1 contain a true value outside of the array bounds.
Error in dat_proc2 (line 58)
speeds{n+1,4} = New_Data{:,3}(indexes,:);
But if i just look at data 3 (test 3) alone it seems to work but as soon as i look at it with the other 2 tests i get this error.
I think it may be the indexing. If anyone can help me solve this problem that would be great.
  11 comentarios
Walter Roberson
Walter Roberson el 19 de Feb. de 2019
size(New_Data{:,3},1) is the number of rows in New_Data{:,3} .
length(indices) is the number of entries in the logical mask.
min() of the two gives the smaller of the two values.
indexes(1:L3) is therefore indexing only to the shorter of the two.
So if there are more entries in indexes than there are rows, then only up to the number of actual rows will be considered. If there are more rows then there are entries in indexes, then only up to the number of entries in indexes will be considered.
Note: in the case where there are more rows than entries in indices, you end up indexing with a logical vector that is shorter than what is being indexed. MATLAB defines the result as-if the logical vector were padded out with false to reach the size of what is being indexed.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by