Generate a Sequence in MATLAB

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
Walter Roberson 2012 年 1 月 31 日

0 投票

L1 = reshape(L.',1,[]).'

7 件のコメント

LOKESH
LOKESH 2012 年 1 月 31 日
do i need to do .' at the end..
Walter Roberson
Walter Roberson 2012 年 1 月 31 日
Now, the final .' could be left out.
Walter Roberson
Walter Roberson 2012 年 1 月 31 日
Urrr, I mean "Yes, the final .' could be left out"
LOKESH
LOKESH 2012 年 2 月 1 日
Thanks Walter.Can you brief me about that as i am unable to get its syntax that u have written
Walter Roberson
Walter Roberson 2012 年 2 月 1 日
Experiment with these steps:
L = magic(5)
t1 = L.'
t2 = t1(:)
t3 = t2.'
And see http://www.mathworks.com/help/techdoc/math/f1-85462.html#f1-85511
LOKESH
LOKESH 2012 年 2 月 4 日
Thanks Sir.But with L1 = reshape(L.',1,[]),I am able to convert my 1D image to 2D.But it works only for some images,for rest it gives me errors of
"Access Out of Bounds" OR
"??? Error using ==> reshape
Product of known dimensions, 256, not divisible into total number
of elements, 21845.
Error in ==> rk4_CHEN at 198
C2 = reshape(C1.',M,[]);"
Walter Roberson
Walter Roberson 2012 年 2 月 4 日
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?
Anyhow, as your requirements have changed since your initial question, please post your new requirements.

サインインしてコメントする。

その他の回答 (1 件)

Derek O'Connor
Derek O'Connor 2012 年 1 月 31 日

0 投票

L1 = L(:)'

2 件のコメント

Walter Roberson
Walter Roberson 2012 年 1 月 31 日
That would not take the sequence "row-wise"; it would take them column-wise.
Derek O'Connor
Derek O'Connor 2012 年 1 月 31 日
Sorry, I hadn't noticed the "row-wise".

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by