# Generate a Sequence in MATLAB

2 views (last 30 days)
LOKESH on 31 Jan 2012
I have a 2d NxN image L. I need to convert it to a sequence of pixels L1={k1,k2,....kNxN} row wise

Walter Roberson on 31 Jan 2012
L1 = reshape(L.',1,[]).'
Walter Roberson on 4 Feb 2012
You are using M = 256. The only way to reshape in to a 1D row of pixels row-wise is if M = 1.
If you want to convert in to rows, then the number of rows you use, M, must be divide the number of elements in the matrix.
I notice that 21845, the number of elements in the matrix, is 257 x 85. 257 is, of course, one greater than 256. Please check your code for an off-by-one error.
Also, please be careful about whether you use M as the 2nd or 3rd parameter of the reshape(). Do you want M rows and however many columns that works out to, or do you want M columns and however many rows that works out to?

Derek O'Connor on 31 Jan 2012
L1 = L(:)'
##### 2 CommentsShowHide 1 older comment
Derek O'Connor on 31 Jan 2012
Sorry, I hadn't noticed the "row-wise".