Data changing when I move it from one struct to another

조회 수: 3 (최근 30일)
Mary
Mary 2013년 6월 19일
Hello!
I'm writing a code which pulls data from one struct to a new struct (for organization purposes) from a directory.
For example I move it from something like
% new struct = old struct
b(1).A.eegData = data.eeg_Data
when I do this and call on b(1).A.eegData, I get an answer that looks like this [32 x 1234245] single that I can't view even in variable editor
while the original looks like a nice matrix of columns and rows containing data...
this also happens for smaller sets of data (eg. a 1 X 5 data set)
b(1).A.question1 = oldData.A.q1 (1:5);
I end up with [1 x 5] single instead of ans = 1 2 3 4 5
Am I doing something wrong, or is everything fine and I'm just not familiar with MATLAB to realize how to access my data
Thanks, ML

답변 (2개)

Muthu Annamalai
Muthu Annamalai 2013년 6월 21일
I find your claim surprising, i.e. copying MATLAB data array from one variable to another, changes dimensions. This is very unlikely, and it is a bug if it is true.
For, example, the following code,
>> clear all
>> z=rand(5,100);
>> a(1).b.C = z;
>> size(a(1).b.C)
ans =
5 100
>> size(a(1).b.C)
works as expected, copying and preserves the data dimensions on uninitialized variables
If this is not the case, I am missing something about your data structures. What kind is data.eeg_data ? Is it a struct, cell-array, matrix, strings??

Jan
Jan 2013년 6월 23일
편집: Jan 2013년 6월 23일
It depends on what exactly "I get an answer" means here. When the contents of a struct is displayed in the command window, such abbreviated information is shown.
c.d = rand(2,2)
displays:
c =
d: [2x2 double]
So I think the copy works well and only the display in the command window differs from your expectations.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by