Form a matrix from a structure

3 次查看(过去 30 天)
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
  2 个评论
Andrew
Andrew 2013-2-4
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)
file = zeros(2592,198);
s.data = load('Compressed.dat');
for i = 1:32;
for j = 1:32;
file = data(i,j);
file(:) = {s};
end
end

请先登录,再进行评论。

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-2-4
编辑:Azzi Abdelmalek 2013-2-4
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(:)
  4 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2013-2-4
编辑:Azzi Abdelmalek 2013-2-4
out=struct2cell(x); % x is your struct variable
out(:)
What did you get?
Andrew
Andrew 2013-2-4
this is just part of the whole results. i dont want to crown the whole place with stuff so i just uploaded some of it but it all rather looks likes this. [1x90 char] '00000000100000000011000000010000000001111111110010' [1x90 char] [1x190 char] [1x310 char] [1x250 char] [1x150 char] [1x110 char] '0000000100000000010100000001100000010001000011001000000011111110100010' '0000000100000000010100000001100000000011000000111000000000111111100000' '00000001000000000101000000100000000011111111100010' [1x110 char] '0000000100000000010100000000100000000011000010001000000000111111010000' '0000000100000000010100000000100000000011000010001000000000111111010000' [1x110 char] [1x110 char] [1x110 char] [1x130 char] [1x130 char] [1x110 char] . . . .

请先登录,再进行评论。

更多回答(2 个)

Cedric
Cedric 2013-2-4
If it is a cell array and cells contents have matching sizes:
>> doc cell2mat
  4 个评论
Cedric
Cedric 2013-2-4
编辑:Cedric 2013-2-4
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
Andrew 2013-2-4
So what i did was to use DCT to compress a 256*256 greyscale image using a 8*8 block matrix. the compressed data therefore comes out as a 32*32(256/8) data structure. i would like to align the extracted data and then the remaining gaps at the end of the matrix will be filled with zeros. Thats basically what i am doing. just in case you may want to look at the structure. http://ge.tt/7q04jkV/v/1

请先登录,再进行评论。


Andrew
Andrew 2013-2-4
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);

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by