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

non-singleton rhs dimensions

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 50×3 double, tss is 1048576×1 double, as is dir. e = 50.
Many thanks guys

Best 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.