MATLAB: Replacing Data by variable name

MATLAB

Hi All
I have two data set as below
A =
Name subName Type Output Q1 Q2 Q3 Q4
x y xy Person 3 4 5 6
a b ab Animal 2 3 4 5
m n mn Bird 1 2 3 4
s t st None 9 9 9 9
x y NA All 1 1 1 1
B =
Name subName Type Output Q2 Q3
x y xy Person -1 -1
m n mn Bird -2 -2
and I want to replace A's value for given qtrs in B repalced with A so that my new set is
C =
Name subName Type Output Q1 Q2 Q3 Q4
x y xy Person 3 -1 -1 6
a b ab Animal 2 3 4 5
m n mn Bird 1 -2 -2 4
s t st None 9 9 9 9
x y NA All 1 1 1 1
I tried using replacedata with variable names but it gives me error.
I am using Matlab 2013b

Best Answer

If your array is not a cell array, use dataset2cell to convert it
a={ 'Name' 'subName' 'Type' 'Output' 'Q1' 'Q2' 'Q3' 'Q4'
'x' 'y' 'xy' 'Person' [ 3] [ 4] [ 5] [ 6]
'a' 'b' 'ab' 'Animal' [ 2] [ 3] [ 4] [ 5]
'm' 'n' 'mn' 'Bird' [ 1] [ 2] [ 3] [ 4]
's' 't' 'st' 'None' [ 9] [ 9] [ 9] [ 9]
'x' 'y' 'NA' 'All' [ 1] [ 1] [ 1] [ 1]}
b={'Name' 'subName' 'Type' 'Output' 'Q2' 'Q3'
'x' 'y' 'xy' 'Person' [-1] [-1]
'm' 'n' 'mn' 'Bird' [-2] [-2]}
name1=a(1,5:end)
name2=b(1,5:end)
text_a=a(2:end,1:4)
text_b=b(2:end,1:4)
idx_text=find(all(ismember(text_a,text_b),2))+1
idx_names=find(ismember(name1,name2))+4
c=a
c(idx_text,idx_names)=b(2:end,5:end)