Problem in using xlswrite command

1 view (last 30 days)
Ron
Ron on 20 Feb 2019
Commented: madhan ravi on 21 Feb 2019
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 Comments
Geoff Hayes
Geoff Hayes on 20 Feb 2019
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 on 20 Feb 2019
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))

Sign in to comment.

Accepted Answer

Ron
Ron on 20 Feb 2019
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 Comments
Geoff Hayes
Geoff Hayes on 20 Feb 2019
Try converting to a numeric value using double.
madhan ravi
madhan ravi on 21 Feb 2019
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.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!