Sunday 15 September 2013

matlab - Creating a variable with unequal rows -


I want to create a variable that is a pattern in different rows of a matrix (let's say [1]) ). Of course, there is no number of numbers similar to this string in each row.

  A = [0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 0 0 1 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1 1 1 0 1];   

I could:

  for i = 1: n var (i, :) = strfind (A (I, :), [ 1 1]);   

But then the two sides of the equation will not be the same.

Error: ??? Subscriptual assignment dimension mismatch

I try to notify in advance, make matrix with the number of maximum number of this string in each row in the Matrix A (let's say 50).

  for i = 1: n var (i, :) = nan (1,50) end   

followed by the last bit of code And it is not good either, either.

I have also tried:

  i = 1: n var (i, 1: numel (strfind (a (i, :), [1] Error) = Stromphand (A (I, :), [1]] end   

Error: There is no valid target for expression on the left side of the equal sign.

How should I go about doing this?

I hope the output matrix is ​​the word (i, :) which gives me position in the matrix

For example:

  var (1, :) = [1 2 5 8 10 22 48] Var (2, :) = [2 3 4 7 34 45 ] Var (3, :) = [4 5 21 32 3 Thank you!   

In its first attempt: You tried to create a matrix with different lengths of rows

Try in your second: you are already allocated, but then it is again defining var (i, :) Run through , while you tried to put your desired result.

Try: Unfortunately you have a bracket at the end of L- ) With micro missed EFT expression did

seems to work that this code (you make 2 and 3, pre-assigned and fixed bracket) :.

  var = NaN (1, 50); For I = 1: n var (i, 1: numel (strfind (a, i, :), [1 1])) = strfind (a (i, :), [1]] and    

No comments:

Post a Comment