Filter löschen
Filter löschen

How to make an endless calculated matrix?

4 Ansichten (letzte 30 Tage)
Sebastian Ciuban
Sebastian Ciuban am 13 Apr. 2013
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!

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 13 Apr. 2013
Bearbeitet: Andrei Bobrov am 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 Kommentar
Sebastian Ciuban
Sebastian Ciuban am 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by