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?
조회 수: 2 (최근 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!