![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/599365/image.jpeg)
how to program this function
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Stephen23
el 28 de Abr. de 2021
Editada: Stephen23
el 28 de Abr. de 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/599365/image.jpeg)
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.
Respuestas (1)
DGM
el 21 de Abr. de 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 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!