Effacer les filtres
Effacer les filtres

How to make an endless calculated matrix?

4 vues (au cours des 30 derniers jours)
Sebastian Ciuban
Sebastian Ciuban le 13 Avr 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!

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 13 Avr 2013
Modifié(e) : Andrei Bobrov le 13 Avr 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 commentaire
Sebastian Ciuban
Sebastian Ciuban le 13 Avr 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by