Assignment has more non-singleton rhs dimensions than non-singleton subscripts

Hi guys, trying my best to battle through some code but cannot get it to work for my data.
for e = length(WAV(:,1));
k = find(tss==WAV(e,1));
WAV(e,5) = dir(k);
end
WAV is currently 50x3 double, tss is 1048576x1 double, as is dir. e = 50.
Many thanks guys

1 Comment

Today I've selected your code and pressed the "{} Code" button, to make it readable. Please do this by your own in the future. Thanks.

Sign in to comment.

 Accepted Answer

Perhaps you mean:
for e = 1:size(WAV, 1)
k = (tss == WAV(e,1));
WAV(e,5) = dir(k);
end
  1. size(X,1) is more efficient than creating a vector only to measure its length by length(X(:,1).
  2. The for loop requires a start points: "1:n". With only "for k = size(WAV,1)" the loop runs over one index only
  3. I've omitted the find() to use the faster logical indexing.
  4. "dir" is a bad name for a variable, because it shadows the builtin function with the same name. This is not an error, but it causes troubles frequently, when the user wants to access the command again.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 22 Aug 2017

Edited:

Jan
on 22 Aug 2017

Community Treasure Hunt

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

Start Hunting!