Info
此问题已关闭。 请重新打开它进行编辑或回答。
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 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Stephen Jue
2017-6-22
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 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!