Hi every body,
I have a simple function to solve an equation using some date from a table:
function [s] = angle(r2,a2)
syms a1
x=a2*pi/180;
s=(vpasolve(sin(pi-a1)==(r2/0.8)*sin(a1-x),a1))*180/3.14
end
Command Window:
>> r2=[3.89;3.90;3.91]
r2 =
3.8900
3.9000
3.9100
>> a2=[8.87;8.86;8.83]
a2 =
8.8700
8.8600
8.8300
>> param=table(r2,a2)
param =
3×2 table
r2 a2
____ ____
3.89 8.87
3.9 8.86
3.91 8.83
>> stats = rowfun(@angle,param,'OutputVariableNames', {'simulatedMean' })
s =
11.154670370349323645591725425313
s =
11.134816655884783149835261112257
s =
11.089983811612564656965216573319
stats =
3×1 table
simulatedMean
_____________
[1×1 sym]
[1×1 sym]
[1×1 sym]
Every thing is o.k but I have the answers in the table stats in form of 1x1 sym. They should be the values of s= 11.15 , 11.13 , 11.08
Could you please help me. I really appreciate that.

Antworten (1)

VBBV
VBBV am 14 Mär. 2022

0 Stimmen

function s = angle(r2,a2)
Change the return value in function to s

5 Kommentare

Navid karimi
Navid karimi am 14 Mär. 2022
Thanks for your reply. I did it but still have the problem.
r2=[3.89;3.90;3.91]
r2 = 3×1
3.8900 3.9000 3.9100
a2=[8.87;8.86;8.83]
a2 = 3×1
8.8700 8.8600 8.8300
param=table(r2,a2)
param = 3×2 table
r2 a2 ____ ____ 3.89 8.87 3.9 8.86 3.91 8.83
stats = rowfun(@angle,param,'OutputVariableNames', {'simulatedMean'})
s = 
11.154670370349323645591725425313
s = 
11.134816655884783149835261112257
s = 
11.089983811612564656965216573319
stats = 3×1 table
simulatedMean _________________________________ 11.154670370349323645591725425313 11.134816655884783149835261112257 11.089983811612564656965216573319
function [s] = angle(r2,a2)
syms a1
x=a2*pi/180;
s=(vpasolve(sin(pi-a1)==(r2/0.8)*sin(a1-x),a1))*180/3.14
end
Navid karimi
Navid karimi am 15 Mär. 2022
I did 'copy paste' your code exactly but still doesn't work. I don't know why.
Torsten
Torsten am 15 Mär. 2022
If you add the line
s = double(s)
in function "angle", what do you get ?
Navid karimi
Navid karimi am 15 Mär. 2022
Bearbeitet: Navid karimi am 15 Mär. 2022
Thanks @Torsten now the table shows correctly.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 14 Mär. 2022

Bearbeitet:

am 15 Mär. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by