Filter löschen
Filter löschen

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 Ansicht (letzte 30 Tage)
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?

Akzeptierte Antwort

Image Analyst
Image Analyst am 19 Sep. 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

Weitere Antworten (1)

Stephen23
Stephen23 am 17 Sep. 2015
Bearbeitet: Stephen23 am 17 Sep. 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 Kommentare
seema niran
seema niran am 19 Sep. 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?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by