フィルターのクリア

how to program this function

1 回表示 (過去 30 日間)
t sizzle
t sizzle 2021 年 4 月 21 日
コメント済み: Rena Berman 2021 年 5 月 6 日
I am trying to program a function (as a separate matlab function, not in the main script) which takes values for variables from different arrays and uses them in the calculation. Here is the function
I am running into a problem because I need to test every A and B value for each coordinate ([1,8], [3,9], [4,2], [9,4]), but since the arrays are different sizes it keeps returning errors.
None of the methods I have tried has worked. The different example arrays I have are as follows.
a = [2:0.2:20];
b = [2:0.2:20];
x = [1,3,4,9];
y = [8,9,2,4];
%numerical values will change based on parameters the user enters. Will
%always be the same size though.
  2 件のコメント
Stephen23
Stephen23 2021 年 4 月 28 日
編集済み: Stephen23 2021 年 4 月 28 日
Original question retrieved from Google Cache:
how to program this function
I am trying to program a function (as a separate matlab function, not in the main script) which takes values for variables from different arrays and uses them in the calculation. Here is the function
I am running into a problem because I need to test every A and B value for each coordinate ([1,8], [3,9], [4,2], [9,4]), but since the arrays are different sizes it keeps returning errors.
None of the methods I have tried has worked. The different example arrays I have are as follows.
a = [2:0.2:20];
b = [2:0.2:20];
x = [1,3,4,9];
y = [8,9,2,4];
%numerical values will change based on parameters the user enters. Will
%always be the same size though.
Rena Berman
Rena Berman 2021 年 5 月 6 日
(Answers Dev) Restored edit

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

回答 (1 件)

DGM
DGM 2021 年 4 月 21 日
Reorient the vectors. If you're using R2016b or newer, you can do this:
c = sum(sqrt((a-x').^2 + (b-y').^2),1)
otherwise, you can use bsxfun(). The point is to generate a distance vector for each x,y pair, resulting in a 2D array. Then just sum the rows.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by