Info
This question is closed. Reopen it to edit or answer.
Trying to create code that will add two matrices together regardless if they have different dimensions or not. The loop will run but it gives me no final summed matrix, saying the variable is undefined, does anyone know how to fix this?
1 view (last 30 days)
Show older comments
The code I wish to create should be able to take any two matrices and concatenate them to create equal sized matrices to be added together. I am using a loop that should account for every situation of different dimensions. Here is the code I have so far, it runs with no problem but will not provide a final matrix.
if row_left_elev == row_right_elev while column_left_elev == column_right_elev step_elevation = left_strides_elevation + right_strides_elevation
if row_left_elev > row_right_elev
while column_left_elev > column_right_elev
matrix_A = zeros(row_right_elev, difference_between_elev_column)
new_right_column_elev = [right_strides_elevation, matrix_A]
matrix_B = zeros(difference_between_elev_rows, column_right_elev)
new_right_strides_elevation = [new_right_column_elev; matrix_B]
step_elevation = left_strides_elevation + new_right_strides_elevation
if row_left_elev < row_right_elev
while column_left_elev < column_right_elev
matrix_A = zeros(row_left_elev, difference_between_elev_column)
new_left_column_elev = [left_strides_elevation, matrix_A]
matrix_B = zeros(difference_between_elev_rows, column_left_elev)
new_left_strides_elevation = [new_left_column_elev; matrix_B]
step_elevation = new_left_strides_elevation + right_strides_elevation
if row_left_elev > row_right_elev
while column_left_elev == column_right_elev
matrix_A = zeros(difference_between_elev_rows, column_right_elev)
new_right_strides_elevation = [right_strides_elevation; matrix_A]
step_elevation = left_strides_elevation + new_right_strides_elevation
if row_left_elev < row_right_elev
while column_left_elev == column_right_elev
matrix_A = zeros(difference_between_elev_rows, column_left_elev)
new_left_strides_elevation = [left_strides_elevation; matrix_A]
step_elevation = new_left_strides_elevation + right_strides_elevation
if row_left_elev == row_right_elev
while column_left_elev > column_right_elev
matrix_A = zeros(difference_between_elev_rows, column_right_elev)
new_right_strides_elevation = [right_strides_elevation; matrix_A]
step_elevation = left_strides_elevation + new_right_strides_elevation
if row_left_elev == row_right_elev
while column_left_elev < column_right_elev
matrix_A = zeros(difference_between_elev_rows, column_left_elev)
new_left_strides_elevation = [left_strides_elevation; matrix_A]
step_elevation = new_left_strides_elevation + right_strides_elevation
if row_left_elev > row_right_elev
while column_left_elev < column_right_elev
matrix_A = zeros(difference_between_elev_rows, column_right_elev)
new_right_row_elev = [right_strides_elevation; matrix_A]
matrix_B = zeros(rows_left_elev, difference_between_elev_column)
new_left_column_elev = [left_strides_elevation, matrix_B]
step_elevation = new_left_column_elev + new_right_row_elev
if row_left_elev < row_right_elev
while column_left_elev > column_right_elev
matrix_A = zeros(difference_between_elev_rows, column_left_elev)
new_left_row_elev = [left_strides_elevation; matrix_A]
matrix_B = zeros(rows_right_elev, difference_between_elev_column)
new_right_column_elev = [right_strides_elevation, matrix_B]
step_elevation = new_left_row_elev + new_right_column_elev
end
0 Comments
Answers (1)
Stephen Jue
on 22 Jun 2017
Hi,
Could you provide the entire function, or an example of how this code runs with two matrices? It is unclear what some of these variables are and how they relate to the matrices (e.g. "row_left_elev", "column_right_elev", etc.)
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!