how to convert character array to cell array

hello, i have a char array of size 1280 * 8 ... values like 11111111 01010101 10100101 ........ 01010101 Now i want as 1*10240 cell array (since 1280 * 8 =10240)...output must be 1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1.....i used str2num ..but they were being conatanated as vertical..i want to conctanate horizantally/..

 Accepted Answer

num2cell(reshape(X.',1,[]))

13 Comments

and now i want this A cell array having size 1*10240 as 20 * 512... i used reshape(A,[20,512])...but those are conacatanating vertically...
Stephen23
Stephen23 on 25 Jul 2017
Edited: Stephen23 on 25 Jul 2017
-"but those are conacatanating vertically..."_
I have no idea what that means. The code I gave puts each element of the input char array into one cell. Perhaps you should check the size of the input char array.
i got befor one...thanks for that now am asking new one...i have a cell array "A" of size 1*10240...i want this cell array as 20 * 512 size... i used reshape(A,[20,512])....but that is not correct
"but that is not correct"
I have no idea what that means. Do you mean that your algorithm is incorrect, or that the code is correct but give an unexpected output, or that the code throws an error? If so, what is the complete error message?
I am getting unexpected output.. If cell array is like 1 0 0 1 0 1 0 1 0 0 ...... 1 0 1 (size 1*10240)... now i want output as 1 0 0 1 0 1 0 0....(upto 20 values) next 20 values...so on upto 512 columns....
@Jyothi Alugolu: and what output do you get?
i got output as 20 * 512 only...but values are not correct... values are splitting in vertical order..i want them to split in horizintal way...
@Jyothi Alugolu: I am happy to help you but you need to be much more precise in your description. Please provide a small sample input data and the expected output data. You can upload files by clicking the paperclip button.
Thanks for bearing me... I will explain once again I have a cell array "A" having 0's and 1's of size 1*10240... Now, i want the output cell array of size 20 * 512.. i.e i cell array needs to be spitted with 20 rows and 512 columns since 20 * 512= 10240...i.e first 512 values in 1st row and then next row must start with 513 th cell value...i used reshape command...what i am getting is wrong..what i got is first 20 values are in 1st column and 2nd column starts with 23rd cell value...but what i want is rowwise splitting... i used reshape(A,20,512)...
"...I will explain once again..."
I did not ask for you to explain it again. Please see my last comment.
i have attached 2 files...f1{1,1} cell size is 1*10240...n the output cell f{1,1} is of size 20 * 512.. i want f1 cell array values to split horizontally..i.e 1st 512 values in 1st row and 2nd row must start with 513th value...but what i got in f{1,1} is first 20 values in 1st column and 2nd column starts with 21st value..i want values to split rowwise..not as columnwise...
reshape(C,[512,20]).'
Because MATLAB is column-major, so matrix vectorization goes along the columns first.
yeah ok..i got it..thank you soo much..

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!