Form a matrix from a structure

1 回表示 (過去 30 日間)
Andrew
Andrew 2013 年 2 月 4 日
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 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 4 日
can you provide an example
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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by