Creating a new matrix by interpolating two other matrices

Hello,
I need to write a code that creates a new matrix C based on the values of matrix A and B, where A and B are 61x10 matrices. Each column of the matrices represents a variable that is common for both A and B and needs to be computed for the new matrix C by interpolating between the columns of these two matrices.
I need to formulate this as a matlab code, but not sure how to start. Do I need to use any built-in function to do the interpolation, or would it be fine to write the interpolation function by myself? Also, I have a total of 10 columns (corresponding to 10 different variables), how do I write the for loop such that the calculations are done for each of the variables (columns) over their 61 values (rows)?
I hope my question makes sense. Thanks in advance.

 採用された回答

dpb
dpb 2015 年 5 月 9 日

1 投票

The beauty of Matlab is that it is vectorized to operate over arrays so you really don't have to do anything special. BUT, you do have to define the problem well enough to have a solution (the Mind Reading Toolbox is yet to be delivered :) ).
What is the interpolating variable between the two arrays? If a simple average is sufficient then
C=(A+B)/2;
works; otherwise add an appropriate weighting to A and B--
C=w*A+(1-w)*B;
for
0<w<1
(The average is just w=0.5, of course)

3 件のコメント

Summer
Summer 2015 年 5 月 9 日
I'm discovering new things each day. Thanks for answering my question! :)
dpb
dpb 2015 年 5 月 9 日
And, BTW, if w is dependent upon the position rather than a fixed value overall as the average or above, then use the "dot" operators..
C=w.*A+(1-w).*B;
where w has the same dimensions as A and B.
Summer
Summer 2015 年 5 月 10 日
Noted. Thank you.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 5 月 9 日

1 投票

What's wrong with the obvious averaging????
C = (A+B)/2;

3 件のコメント

Summer
Summer 2015 年 5 月 9 日
It's because I have to include the effect of some other variable; or weight as dpb called it. Anyways, thanks for answering. :)
Image Analyst
Image Analyst 2015 年 5 月 9 日
Ah - a key bit of information you didn't explicitly state (though I wondered about before posting). What is w?
Summer
Summer 2015 年 5 月 9 日
Sorry for that. My w in this case is: w= (Q-Q1)/(Q2-Q1), where Q1 is used to generate the first matrix A, and Q2 is used to generate the second matrix B. Q is the new rate for which I need to interpolate the values of the two matrices A and B to generate a new one. All of the Q's are scalar values.

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

カテゴリ

ヘルプ センター および File ExchangeInterpolation についてさらに検索

質問済み:

2015 年 5 月 9 日

コメント済み:

2015 年 5 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by