Borrar filtros
Borrar filtros

i have a matrix A of 1 column and another B of 4 columns. need to do some operations of A with each column of B and to get answer as C1,C2,C3,C4 using loops . Is it possible?

1 visualización (últimos 30 días)
i have a matrix A of 1 column and another B of 4 columns. need to do some operations of A with each column of B and to get answer as C1,C2,C3,C4 using loops . Is it possible?

Respuesta aceptada

Image Analyst
Image Analyst el 19 de Sept. de 2015
Perhaps this, which will do a fit of each column of (the badly-named) B vs. A:
% A is the x values,
% Columns of B are the y values
for col = 1 : size(B, 2)
thisColumn = B(:, col);
% Fit a line through these data points in this column.
coefficients = polyfit(A, thisColumn, 1);
slopes(col) = coefficients(1);
intercepts(col) = coefficients(2);
end

Más respuestas (1)

Stephen23
Stephen23 el 17 de Sept. de 2015
Editada: Stephen23 el 17 de Sept. de 2015
The best solution would be to not create numbered variables, but to simply keep all of the data together in one numeric array. Doing this makes MATLAB code much faster and neater. You can simply use indexing to access that parts of that array than you need to.
If you tell us what those "operations" are then we could tell you effective and efficient ways of doing those operations.
Whatever you do you should not create those variables dynamically. This is a poor programming practice that beginners seem to love. Read this to know why creating variables dynamically is a really bad idea:
  3 comentarios
seema niran
seema niran el 19 de Sept. de 2015
i tried m= ones([4749 24]); then to multiply answer during each iteration to the columns of m. but it gives me a [4749 1 ] matrix. how to get a [4749 24] matrix as the final answer?

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by