Why do I get: "Error using vertcat Dimensions of matrices being concatenated are not consistent."
1 view (last 30 days)
Show older comments
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
1 Comment
Stephen23
on 1 Apr 2015
Note that it is a bad idea to name a variable |single, as this is the name of the inbuilt function single.
Accepted Answer
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.
2 Comments
More Answers (1)
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.
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!