フィルターのクリア

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 回表示 (過去 30 日間)
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?

採用された回答

Image Analyst
Image Analyst 2015 年 9 月 19 日
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

その他の回答 (1 件)

Stephen23
Stephen23 2015 年 9 月 17 日
編集済み: Stephen23 2015 年 9 月 17 日
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 件のコメント
John D'Errico
John D'Errico 2015 年 9 月 17 日
So? Then use a loop, and stuff the results into another matrix.
seema niran
seema niran 2015 年 9 月 19 日
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?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by