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

댓글 수: 3

Neesha
Neesha 2014년 6월 12일
looks like text not coming out well, here is an image
Azzi Abdelmalek
Azzi Abdelmalek 2014년 6월 12일
편집: Azzi Abdelmalek 2014년 6월 12일
What are the classes of your data, cell or dataset?
Neesha
Neesha 2014년 6월 12일
Dataset

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

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 6월 13일

0 개 추천

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)

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 6월 12일

0 개 추천

Do you have R2013b or later? If so, just use a table.

댓글 수: 4

Neesha
Neesha 2014년 6월 12일
I have R2013b
Neesha
Neesha 2014년 6월 12일
But what do i do using table?
Did you use
tableA = readtable(ExcelFileName);
to read the Excel file into a table (a wonderful new data type started with R2013b)? Please attach the workbook if you want people to try things.
First you need to identify which rows need to get replaced. You do that with ismember(). Then it's straightforward and I think would go something like this ( very untested and just off the top of my head )
for currentRow = 1 : length(tableB.Q2)
% Find rows in A that need to be replaced.
rowsToReplace = ismember(tableB.name(currentRow), tableA.name);
% Replace all the rows in A that need replacing with the value from B.
for rowsInA = find(rowsToReplace)
tableA.Q2(rowsInA) = tableB.Q2(currentRow);
tableA.Q3(rowsInA) = tableB.Q3(currentRow);
end
end
You should also check subname.
Neesha
Neesha 2014년 6월 12일
ok, i will make sure to attach file next time.
Here is the thing, my A and B are internal to code and not in the file. Those are output from a function. So i am trying to figure to convert them into table

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

카테고리

도움말 센터File Exchange에서 Calendar에 대해 자세히 알아보기

제품

태그

아직 태그를 입력하지 않았습니다.

질문:

2014년 6월 12일

댓글:

2014년 6월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by