How to make an endless calculated matrix?

3 views (last 30 days)
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!

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 13 Apr 2013
Edited: Andrei Bobrov on 13 Apr 2013
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 Comment
Sebastian Ciuban
Sebastian Ciuban on 13 Apr 2013
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

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!