i want to concatenate two variable but getting an error..."Names of fields in structure arrays being concatenated do not match. Concatenation of structure arrays requires that these arrays have the same set of fields"

조회 수: 3 (최근 30일)
I want to concatenate two variables. first i loaded my data which is a matrix, to both variables then store particular part of variables in another variable and then concatenate them. Here is my code.
t=load('2');
v=load('3');
T.a =t(:,2:size(t,2));
c=v(:,2:size(v,2));
ans=cat(2,T.a,c);
Here '2','3' are my files.
but i am getting error...
Error using cat Names of fields in structure arrays being concatenated do not match. Concatenation of structure arrays requires that these arrays have the same set of fields.
Error in Untitled3 (line 5) ans=cat(2,T.a,c); i think becoz when i load data it stores in variables with different field names.
Plz provide some solution . i have to use it
  댓글 수: 2
KSSV
KSSV 2016년 12월 7일
편집: KSSV 2016년 12월 7일
What data the files have? Why don't you attach files if possibles?
MAYANK RATHORE
MAYANK RATHORE 2016년 12월 9일
편집: MAYANK RATHORE 2016년 12월 9일
Sir my data is nothing but simply a matrix ,suppose a 3*3 matrix.As i am loading it to a variable it comes with a field value.And whenever i have to copy that data i have to mention the field value ,which is given by matlab.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2016년 12월 7일
A bold guess:
File2Data = load('2');
t = File2Data.t;
File3Data = load('3');
v = File3Data.v;
T.a = t(:, 2:size(t,2));
c = v(:, 2:size(v,2));
Reply = cat(2, T.a, c);
load replies a struct, not the values directly. You can check this manually.
  댓글 수: 3
Jan
Jan 2016년 12월 9일
The field names are defined by the names of the variables during saving. So they are not "random". But if you do not know the names:
Data = load(FileName);
Fields = fieldnames(Data);
for k = 1:length(Fields)
disp(Data.(Fields{k}))
end
MAYANK RATHORE
MAYANK RATHORE 2016년 12월 9일
Sir ur example of display field name is very nice but as u say in first line "fieldnames are defined by the names of variable" .Suppose I am loading my data in MYDATA variable ,but it stored with field name 'a' and whenever i want to access the data i have to write MYDATA.a .This is the problem this fieldname is given my matlab. And also, whenever i stored it as MYDATA.t it will store as MYDATA.T.a .

댓글을 달려면 로그인하십시오.

카테고리

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