Azzera filtri
Azzera filtri

how to program this function

1 visualizzazione (ultimi 30 giorni)
t sizzle
t sizzle il 21 Apr 2021
Commentato: Rena Berman il 6 Mag 2021
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 Commenti
Stephen23
Stephen23 il 28 Apr 2021
Modificato: Stephen23 il 28 Apr 2021
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 il 6 Mag 2021
(Answers Dev) Restored edit

Accedi per commentare.

Risposte (1)

DGM
DGM il 21 Apr 2021
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.

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by