How to make an endless calculated matrix?

조회 수: 2 (최근 30일)
Sebastian Ciuban
Sebastian Ciuban 2013년 4월 13일
For example I have matrix A(3,2) = [2 3; 4 5; 6 7] and matrix B(3,1) = [A(1,1)+A(1,2); A(2,1)+A(2,2); A(3,1)+A(3,2)]
Now, maybe I want to add 2 more rows in matrix A and I want B calculate those element without me writing A(4,1)+A(4,2) etc, automatically. For matrix A of ,,n" rows and 2 columns I want to make a B matrix of ,,n" rows and 1 column, B depending on A. Is there some set of commands to make this possible?
EDIT: What I really need is to know how to build matrix B ,which depends on A, using functions.
For example, we got: -*matrix* A(3,2)*= [2 3; 4 5; 6 7] -a function to calculate: sqrt(A(1,1)+A(1,2))/2 -*matrix* B(3,1)= [Function(A(1,1),A(1,2)); Function(A(2,1),A(2,2)); Function(A(3,1),A(3,2))] Now how can I build matrix B regardless of rows that matrix A have, without my input for every row in matrix B *Note: English is not my first language and I may not be very explicit.
Thank you!

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 4월 13일
편집: Andrei Bobrov 2013년 4월 13일
A = [2 3; 4 5; 6 7];
B = sum(A,2);
A(end+1,:) = [4 9]
B(end+1,:) = sum(A(end+1,:),2);
ADD
fun = @(x)sqrt(sum(x,2))/2;
B= fun(A);
  댓글 수: 1
Sebastian Ciuban
Sebastian Ciuban 2013년 4월 13일
Thank you, indeed in this case it really works. What I really need is to know how to build matrix B ,which depends on A, using functions.
For example, we got: -*matrix* A(3,2)*= [2 3; 4 5; 6 7] -a function to calculate: sqrt(A(1,1)+A(1,2))/2 -*matrix* B(3,1)= [Function(A(1,1),A(1,2)); Function(A(2,1),A(2,2)); Function(A(3,1),A(3,2))] Now how can I build matrix B regardless of rows that matrix A have, without my input for every row in matrix B

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by