Error in importing the matlab ouput to excel file
1 次查看(过去 30 天)
显示 更早的评论
i wrote the code for non linear equations and i got the result cubic roots. The problem is that i have to import the results to excel file . i use the command xlswrite but i am getting the error unable to convert the data. could anyone tell me to solve this issue. i am attaching my code below
clear all
close all
syms N
Qo=xlsread('suspended.xlsx','A:A')
R=xlsread('suspended.xlsx','B:B')
No=xlsread('suspended.xlsx','C:C')
X=xlsread('suspended.xlsx','D:D')
r = (No-N)./No ;
V = 2435 ;
k = 1.076 ;
Kn = 0.27 ;
nX = size(X,1 );
solutions = cell(nX,1 );
for S=1:nX
solutions{S} = solve(Qo(S) .* (1+R(S)) .* (No(S)-N) .* r(S) - V*((X(S)*k*N)./(Kn+N)), N );
vpa(solutions{S },5)
xlswrite(ans,'suspended.xlsx')
0 个评论
回答(2 个)
Bob Thompson
2021-1-19
It looks like you're trying to output a symbolic variable to excel, which I don't think is allowed. Try converting to double first.
vpa(solutions{S },5)
double(ans)
xlswrite(ans,'suspend.xlsx')
5 个评论
Bob Thompson
2021-1-19
I suppose you could convert to strings in that case. My little bit of research indicates it's not nearly as pretty, but it would be possible to break the results out into a string array which could be exported to excel.
Walter Roberson
2021-1-19
WIth the particular data that the user posted, it happens that the roots are all real-valued (though some of them are negative.)
Walter Roberson
2021-1-19
syms N
Qo = xlsread('suspended.xlsx','A:A');
R = xlsread('suspended.xlsx','B:B');
No = xlsread('suspended.xlsx','C:C');
X = xlsread('suspended.xlsx','D:D');
r = (No-N)./No ;
V = 2435 ;
k = 1.076 ;
Kn = 0.27 ;
nX = size(X,1 );
solutions = cell(1, nX);
for S=1:nX
solutions{S} = solve(Qo(S) .* (1+R(S)) .* (No(S)-N) .* r(S) - V*((X(S)*k*N)./(Kn+N)), N );
end
sold = cell2mat(cellfun(@(C) round(double(C),5), solutions, 'uniform', false ));
sold
xlswrite('suspended.xlsx', sold)
This creates the roots as rows of the output, with the columns corresponding to original data rows form the xlsx file. Or it would be easy enough to write sold.' to have the columns be the roots and the rows correspond to the original data rows from the xlsx file.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!