Anonymous function only returns single answer
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Alexander
am 21 Mär. 2023
Kommentiert: Matt J
am 22 Mär. 2023
I have a function where its inputs are two arrays. How do I get the function to return an array of values rather than one single value? The value returned for b is -5.6e-4. Thanks
Code shown here:
x=pi:pi/100:2*pi;
y=x.^2;
z = @(a,b) ((sin(a)+cos(b))/((a.^2)+(b.^2)));
b = z(x,y);
0 Kommentare
Akzeptierte Antwort
Matt J
am 21 Mär. 2023
Bearbeitet: Matt J
am 21 Mär. 2023
Use the elementwise division operator ./
x=pi:pi/100:2*pi;
y=x.^2;
z = @(a,b) ((sin(a)+cos(b))./((a.^2)+(b.^2)));
b = z(x,y)
2 Kommentare
Matt J
am 22 Mär. 2023
You're quite welcome, but please Accept-click the answer to indicate that your question is resolved.
Weitere Antworten (0)
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!