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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by