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.

답변 (1개)

VBBV
VBBV 2022년 3월 14일

0 개 추천

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

댓글 수: 5

Navid karimi
Navid karimi 2022년 3월 14일
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 2022년 3월 15일
I did 'copy paste' your code exactly but still doesn't work. I don't know why.
Torsten
Torsten 2022년 3월 15일
If you add the line
s = double(s)
in function "angle", what do you get ?
Navid karimi
Navid karimi 2022년 3월 15일
편집: Navid karimi 2022년 3월 15일
Thanks @Torsten now the table shows correctly.

댓글을 달려면 로그인하십시오.

카테고리

태그

질문:

2022년 3월 14일

편집:

2022년 3월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by