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
답변 (1개)
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
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!