0

From the following code, I want to generate a matrix from the colon operator through a for-loop and have starting and ending values given in ends(20x2 double) where 1st and 2nd column of ends is the starting and ending values respectively.

for hh=1:length(ends)
xx{:,hh}=ends(hh,1)-1:ends(hh,2)+1;
end

and it is giving me the following error message

Expected one output from a curly brace or dot indexing expression, but there were 0 results.

Error in new_one (line 11) 
xx{:,hh}=ends(hh,1)-1:ends(hh,2)+1;
Michael M.
  • 10,486
  • 9
  • 18
  • 34

1 Answers1

2

The error is likely due to an incorrect combination of xx{:,hh}=... with an incompatible initialization of xx, such as xx={}, which prevents : from evaluating to any row number. The following code should work:

% Simulated data
ends=randi(16,[20 2]);
ends=[min(ends,[],2) max(ends,[],2)];

% Create cell array
xx=cell([1 size(ends,1)]);
for hh=1:size(ends,1)
  xx{hh}=ends(hh,1)-1:ends(hh,2)+1;
end
Vicky
  • 969
  • 1
  • 11
  • 19