Why do I get: "Error using vertcat Dimensions of matrices being concatenated are not consistent."

1 view (last 30 days)
I have a vector, which should be splitted at certain points (if condition). The parts of the vector should emerge as column in a matrix. In a for-loop I want to establish the new matrix step by step. I have made some preallocation, but I still get an error message. Can someone help me? Here is my code:
Entire = zeros (d,e); %preallocation
for b = 1: lengthRS
if trigger (b,1) ==1 && trigger (b+1) == 1; %condition for splitting
single = ERGsignal(b:b+d,1); %make single part of vector (ERGsignal)
Entire = [Entire; single]; %Building up Matrix
end
end

Accepted Answer

Torsten
Torsten on 1 Apr 2015
Does this work ?
Entire = [];
for b = 1: lengthRS
if trigger (b,1) ==1 && trigger (b+1,1) == 1; %condition for splitting
single = ERGsignal(b:b+d,1); %make single part of vector (ERGsignal)
Entire = horzcat(Entire, single); %Building up Matrix
end
end
Best wishes
Torsten.

More Answers (1)

James Tursa
James Tursa on 1 Apr 2015
Edited: James Tursa on 1 Apr 2015
Entire has e columns
single has 1 column
So unless e == 1, they won't match and hence the error. That being said, it looks like maybe you intended to build up Entire by columns instead of rows. If so, use a comma instead of a semi-colon when attaching "single" (and adjust the size of Entire accordingly).
"single" is an extremely poor choice for a variable name btw since it matches a MATLAB class name. I would advise choosing a different name for this variable.

Community Treasure Hunt

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

Start Hunting!