MATLAB: 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

loops

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?

Best Answer

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