how to concatenate two fields in a struct ?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
hi...i want to concatenate fields namels data and text data below,how to do this? textdata is the label name for the maindata...any suggestion ?
struct(1*1)
maindata(138*173 double)
textdata(138*1 cell)
0 Kommentare
Akzeptierte Antwort
Geert
am 6 Sep. 2013
Sandy,
it is still very unclear what you exactly want. In what format do you want your output data?
Do you want something like the following example?
cc = struct;
cc.maindata = [0 +1.193790E+1 +5.275883E+0 +1.796951E+1;
0 +1.188781E+1 +6.487981E+0 +1.919098E+1
0 +1.175415E+1 +5.493386E+0 +1.851824E+1];
cc.textdata = {'SAMPLE_20130606_1358'; 'SAMPLE_20130606_1408'; 'SAMPLE_20130606_1418'}
concatenateddata = cell(size(cc.maindata,1),size(cc.maindata,2) + size(cc.textdata,2));
for ii = 1:size(cc.maindata,1)
concatenateddata{ii,1} = cc.textdata{ii};
for jj=1:size(cc.maindata,2)
concatenateddata{ii,jj+1} = cc.maindata(ii,jj);
end
end
1 Kommentar
Weitere Antworten (1)
Geert
am 6 Sep. 2013
Can you be more specific?
Do you want to convert the (double) data in maindata to a string, and concatenate it to the strings in the cell array textdata? In that case, here is an example code snippet on how to do it:
cc = struct;
cc.maindata = [1 2;3 4; 5 6];
cc.textdata = {'firststring'; 'secondstring'; 'thirdstring'}
concatenateddata = cell(3,1);
for ii = 1:size(cc.maindata,1)
concatenateddata{ii} = [num2str(cc.maindata(ii,:)),' ', cc.textdata{ii}];
end
Please make your question more understandable.
2 Kommentare
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!