adding rows to array with order
이전 댓글 표시
data=[1.0452;1.0645;1.1027;1];
fixed_data=[1;1.0452];
for i=1:numel(fixed_data)
idx(i)=find(fixed_data(i)==data);
end
other_data=[1.064562;1.102656];
I need to merge fixed_data and other_data w.r.t idx as follows;
merged_data=[1.0452;1.064562;1.102656;1];
idx (4 1) determines 4th row of merged_data equals fixed_data(1) and first row of merged data equals fixed_data(2). Matrix dimensions are variable so I need to perform this as an automatic way for any situation.
채택된 답변
추가 답변 (1개)
Azzi Abdelmalek
2016년 5월 19일
편집: Azzi Abdelmalek
2016년 5월 19일
data=[1.0452;1.0645;1.1027;1]
fixed_data=[1;1.0452]
other_data=[1.064562;1.102656]
%---------------------------------
merged_data=data
idx=ismember(data,fixed_data)
merged_data(idx)=fixed_data
merged_data(~idx)=other_data
댓글 수: 3
sermet
2016년 5월 19일
Azzi Abdelmalek
2016년 5월 19일
Use
format long
merged_data
you will see the difference
카테고리
도움말 센터 및 File Exchange에서 Oscilloscopes에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!