Asked by Andrew
on 4 Feb 2013

I have a 32*32 data structure. There are 1*1 structures in each of those 32*32 cells. However, i would like to extract all the binary data in the substructures and align them into one matrix. any one with some code that could help me do this please? Thank you

*No products are associated with this question.*

Answer by Azzi Abdelmalek
on 4 Feb 2013

Edited by Azzi Abdelmalek
on 4 Feb 2013

Accepted answer

Try

x(1,1).data=1; x(1,2).data=[2 1]; x(2,1).data=rand(2); x(2,2).data=[1;2]; out=struct2cell(x); out(:)

Show 1 older comment

Azzi Abdelmalek
on 4 Feb 2013

out=struct2cell(x); % x is your struct variable out(:)

What did you get?

Andrew
on 4 Feb 2013

Answer by Cedric Wannaz
on 4 Feb 2013

If it is a cell array and cells contents have matching sizes:

>> doc cell2mat

Show 1 older comment

Cedric Wannaz
on 4 Feb 2013

`cell2mat`. Sizes can vary, but they have to match between adjacent blocks. If your aren't in this situations, you'll have to define what how you want to manage gaps (e.g. fill them with NaNs so sizes match..?).

Cedric Wannaz
on 4 Feb 2013

Seems that you edited the question since I posted my answer. Seeing your answer to Azzi, you should just look at what are these variables that you are dealing with, e.g.

>> S = load('Compressed.dat') ; S = ans: {...} data: {...} >> class(S) ans = struct >> class(S.data) ans = cell >> size(S.data) ans = 32 32

... doing that would help you truly understand the structure of the objects that you are dealing with, which will allow you to index them correctly.

Andrew
on 4 Feb 2013

Answer by Andrew
on 4 Feb 2013

Thanks to Azzi and Cedric o was able to get a step forward. however my question now is, i have managed to extract all the binary digits from the structure and they are in a file. i would like to rearrange them into a matrix of 2592*2592. how do i do that? Below is my final code for extracting the binary digits(or bits??)

load('Compressed.mat'); %load compressed data fid = fopen('saved_data.txt','w'); for i = 1:32; for j = 1:32 fwrite(fid,I_runcode(i,j).code); end end fclose(fid);

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 2 Comments

## Azzi Abdelmalek (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/62100#comment_126894

can you provide an example

## Andrew (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/62100#comment_126896

i am trying to write out something but just thought i needed help. this is what i have sofar. (2592,198) is the size of the matrix i would like to have my data in.(I hope this is what you meant by example)