0
votes

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. What does this mean?

Error in segment(n_start)=data(n_start:(n_start+ window_size-1));

%% input data matrix
DDD=load('data2.mat');
data=DDD.data;
N_max=length(data);
window_size=256*3; %% 256 for 1 second ==> 3 seconds
step_win=128*3; %% overlapping window ...by 50%
segment=zeros(4798,768);
count=0;
for n_start = 1:step_win:(N_max-window_size)
    count=count+1;
    segment(n_start)=data(n_start:(n_start+ window_size-1));
end
plot(Segment)
xlabel('time')
grid on;
title('data of channel1');
1
You don't say where you got the error (always include the entire error message), but I assume it's on the line assigning Segment(n_start) where you're trying to fit a 768-element vector into a single array element. I don't think that's what you want to do. Also, you should check your variable names. You initialize segment but assign Segment. Those are not the same.beaker
I want the array segment=zeros(4798,768) to be filled each time the loop iterategehan

1 Answers

0
votes

In the passage:

segment(n_start)=data(n_start:(n_start+ window_size-1));

You are attempting to attribute a vector into a 1x1 matrix.

If segment is a vector, then segment(n_start) is its value at the location n_start, if n_start in an integer, then segment(n_start) is 1x1.

On the other hand n_start:(n_start+ window_size-1) is a vector that spans from n_start and increases one by one until (n_start+ window_size-1). And that due to how the : operator works. Because window_size=256*3, then it is a 767-long vector.

When you call data(n_start:(n_start+ window_size-1)), you are asking all the values of data in the indexes contained in the vector n_start:(n_start+ window_size-1).

Hence, in the error line, you trying to atribute a vector of size 767x1 to a 1x1 matrix. that is why it doesn't work.