Problem in using xlswrite command

1 次查看(过去 30 天)
Hello All,
I am trying to get the output in excel file but I am unable to do that. I have attached the screen shot of my code along with some information.
here is the output in Excel and I think that the problem is becuase the result is not a scalar number
I will be great if someone please help me with this.
Thank You
  3 个评论
Geoff Hayes
Geoff Hayes 2019-2-20
Ron - is it just the diameter data that is not being written to the Excel file? I notice that this data is of type sym. Perhaps try converting to a number before writing to file...
Ron
Ron 2019-2-20
Hello Geoff,
Yes, only the diameter data is missing.
Your suggestion helped me to solve the problem. The problem was the data type beign sym. Converting it to number helped.
Ce=0.059;
syms dt1 dt2 dt3 dt4 dt5;
eqns=[locrbm1==((227/dt1)*sqrt(1+Ce*(dt1)^2)), locrbm2==((227/dt2)*sqrt(1+Ce*(dt2)^2)),locrbm3==((227/dt3)*sqrt(1+Ce*(dt3)^2)),locrbm4==((227/dt4)*sqrt(1+Ce*(dt4)^2)),locrbm5==((227/dt5)*sqrt(1+Ce*(dt5)^2)),]
S=solve(eqns,[dt1 dt2 dt3 dt4 dt5]);
dia1=double(vpa(S.dt1))
dia2=double(vpa(S.dt2))
dia3=double(vpa(S.dt3))
dia4=double(vpa(S.dt4))
dia5=double(vpa(S.dt5))
Diameter=[dia1, dia2, dia3, dia4, dia5]
Avedia=mean(Diameter)
stddia=std(Diameter)
errdia=stddia/sqrt(length(Diameter))

请先登录,再进行评论。

采纳的回答

Ron
Ron 2019-2-20
Here is the part of my code
I have attached the output excel file as well. If you check my file then you will see that one of the column is missing data and I think becuase the result is not a scalar number (as it say 1x1 sym for the output data dia)
%Diameter
Ce=0.059;
syms dt1 dt2 dt3 dt4 dt5;
eqns=[locrbm1==((227/dt1)*sqrt(1+Ce*(dt1)^2)), locrbm2==((227/dt2)*sqrt(1+Ce*(dt2)^2)),locrbm3==((227/dt3)*sqrt(1+Ce*(dt3)^2)),locrbm4==((227/dt4)*sqrt(1+Ce*(dt4)^2)),locrbm5==((227/dt5)*sqrt(1+Ce*(dt5)^2)),]
S=solve(eqns,[dt1 dt2 dt3 dt4 dt5]);
dia1=vpa(S.dt1,5)
dia2=vpa(S.dt2,5)
dia3=vpa(S.dt3,5)
dia4=vpa(S.dt4,5)
dia5=vpa(S.dt5,5)
Diameter=[dia1, dia2, dia3, dia4, dia5]
Avedia=mean(Diameter)
stddia=std(Diameter)
errdia=stddia/sqrt(length(Diameter))
%output in Excel
m={'Sample' 'RBM Shift' 'Diameter' 'D-Peak' 'Raman Shift D ' 'G-Peak' 'Raman Shift G' 'G''-Peak' 'Raman Shift G'' ' 'Defect Ratio';'S1' locrbm1 dia1 d1 locd1 g1 locg1 gp1 locgp1 gd1;'S2' locrbm2 dia2 d2 locd2 g2 locg2 gp2 locgp2 gd2;'S3' locrbm3 dia3 d3 locd3 g3 locg3 gp3 locgp3 gd3;'S4' locrbm4 dia4 d4 locd4 g4 locg4 gp4 locgp4 gd4;'S5' locrbm5 dia5 d5 locd5 g5 locg5 gp5 locgp5 gd5; 'Average' avglocrbm Avedia ' ' avglocd ' ' avgloc ' ' avglocgp Avg; 'St. Deviation' sdevlocrbm stddia ' ' sdevlocd ' ' sdevloc ' ' sdevlocgp Sdev; 'Error' errlocrbm errdia ' ' errlocd ' ' errloc ' ' errlocgp Err};
filename = 'testdata.xlsx';
xlswrite(filename,m)
  2 个评论
Geoff Hayes
Geoff Hayes 2019-2-20
Try converting to a numeric value using double.
madhan ravi
madhan ravi 2019-2-21
Ron always remember solve returns a symbolic object so in order to convert it to a double class use double() , vpa() also returns a symbolic object so using vpa() here is superflous.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by