Question
I want to integrate two lines inside matrix and repeated frequently before each rows: The original matrix: A = [ G1 X8 Y118 G1 X8 Y135 G1 X 8 Y 150 G1 X 8 Y 172 G1 X 8 Y 209 G1 X 8 Y 242 G1 X 8 Y 410 G1 X 9 Y 208 …….. ] so on Generated matrix AA = [ M 802 M 800 P 8 G1 X8 Y118 M802 M800 P8 G1 X8 Y135 M 802 M 800 P 8 G1 X 8 Y 150 M 802 M 800 P 8 G1 X 8 Y 172 M 802 M 800 P 8 G1 X 8 Y 209 M 802 M 800 P 8 G1 X 8 Y 242 M 802 M 800 P 8 G1 X 8 Y 410 M 802 M 800 P 8 G1 X 9 Y 208 …………] so on So before any row, put these two rows M802 M800 P8 How can we do this?
Expert Answer
Prashant Kumar
PhD Expert
Answered Nov 20, 2025
Here is the code to integrate two lines inside matrix and repeated frequently before each rows.
A = [ "G"+1 "X"+8 "Y"+118
"G"+1 "X"+8 "Y"+135
"G"+1 "X"+8 "Y"+150
"G"+1 "X"+8 "Y"+170
"G"+1 "X"+8 "Y"+209];
Repeat1 = ["M"+802,"","";"M"+800, "P"+8,""];
rows = size(A,1);
AA = [];
for i = 1:rows
AA = [AA; vertcat(Repeat1, A(i,:))]
end
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related matlab Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →