how to insert an element in an array at a specific index?

how to insert an element in an array at a specific index?
I want to insert x3 at index 16 in x2
load('data.mat');
rows=size(RO_ISR,1);
for i=1:rows
RO=RO_ISR{i,1};
IONOSODE=RO_ISR{i,2};
x1 = RO.EDP8 * 10^6;
y1 = RO.EDP3;
columns=size(RO_ISR,2);
for j=3:columns
ISR=RO_ISR{i,j};
x2 = ISR.NE8;
y2 = ISR.GDALT;
TT1 = table2timetable(ISR);
TT3 = synchronize(IONOSODE, TT1);
F = fillmissing(TT3,'previous');
ISR_date =ISR.Date;
F_date = F.Date;
[logical_Index ,index] = ismember(ISR_date(1),F_date);
x3=IONOSODE{index,10};
y3=IONOSODE{index,7};
y4 = [y2;y3];% add row y2 to column y3
final_altitude=sort(y4); % sort data in asending form
[logical_Index ,index]= ismember(y3,final_altitude);% find index of y3 in final_altitude
figure;
hold on;
plot(x1, y1);
plot(x2, y2);
plot(x3,y3,'*r','MarkerSize',10)
xlabel('Electron Density');
ylabel('Altitude');
title('Plotting');
legend('RO', 'ISR','ionosonde');
hold off;
end
end

댓글 수: 7

Matt J
Matt J 2023년 6월 21일
편집: Matt J 2023년 6월 21일
A toy example to clarify would be greatly beneficial.
Also, your code references a file data.mat that is not attached.
I answered on the above question, but how to insert an element in an array at a specific index ?
Could you please clarify by what you mean by the "index of y3"
Matt J
Matt J 2023년 6월 21일
편집: Matt J 2023년 6월 21일
I answered on the above question
I don't see any changes to the posted question. The attachment is still missing and no example has been added. An example means you show us both the input and the desired output, normally on a smaller piece of example data.
I edited the question
Or give me the function which I can use it to insert
@h, an example of how to insert a value into a specified location of a vector is given below by @Ronit. Scroll down and look at it.

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

 채택된 답변

Ronit
Ronit 2023년 6월 21일
Hi,
To add an element at a specific index in an array, try the following
x2 = [x2(1:15), x3, x2(16:end)]

추가 답변 (0개)

카테고리

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

질문:

t
t
2023년 6월 21일

댓글:

t
t
2023년 6월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by