how to program this function
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Stephen23
am 28 Apr. 2021
Bearbeitet: Stephen23
am 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.
Antworten (1)
DGM
am 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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!