Can't get function to accept array params or return arrays
Ältere Kommentare anzeigen
Consider this function to calculate the slope of a line:
function [m] = f_GetSlope(x1, y1, x2, y2)
m = (y1 - y2)/(x1 - x2);
It works with scalar inputs. But I want to call it like so:
aX1 = [1, 23];
aY1 = [1, 12];
aX2 = [2, 8];
aY2 = [2, 0];
m1 = f_GetSlope(aX1, aY1, aX2, aY2)
Ideally it would return:
m1 = 1 0.800
In actuality:
m1 = 0.8009
Just one return value, and not correct for either set of inputs.
What am I doing wrong?
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!