blockarray = 50 50 50 50 50 50 50 50 50 neededArray = 25.0000 25.0000 25.0000 25
ID: 3910265 • Letter: B
Question
blockarray =
50 50 50
50 50 50
50 50 50
neededArray =
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 37.5000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
StartCpuX = 4
StartCpuY = 2
I want to insert blockarray into neededArray at location (StartCpuX,StartCpuY).
i.e
neededArray =
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 37.5000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 50.0000 50.0000 50.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 50.0000 50.0000 50.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 50.0000 50.0000 50.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000
MATLAB - no loops, just simple matlab, please nothing fancy
Explanation / Answer
As there is no delimiter in the given data to determine the rows and columns of neededArray, it is assumed to be of 11 x 12 order with the consideration of each new line.
Hence, the required MATLAB script will be:
%===========================
blockarray = [50 50 50;50 50 50;50 50 50];
neededArray = [25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000;25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000;25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000;25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000;25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000;25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 37.5000 25.0000 25.0000 25.0000 25.0000 25.0000;25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000;25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000;25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000;25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000;25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000 25.0000];
StartCpuX = 4;
StartCpuY = 2;
% To inser a 3 x 3 matrix at 2,4 we need to alter the submatrix which is
% composed of rows 2 to 4 and columns 4 to 6, hence:
neededArray(2:4,4:6)=blockarray;
display(neededArray);
%=============================
Note: For a different dimensional arrangement of matrix neededArray, the same idea can be extended i.e. only modify the input neededArray.
Hope this helps!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.