how to "write" a equation like string from a number matrix and a vector of varibles, and put those equation into cell to slxwrite to excel ?
1 次查看(过去 30 天)
显示 更早的评论
I have a vector of name of variables like 'cake' 'sandwich' 'key' 'sun' etc, and a matrix of n x m coeff. I need to combine each row of the matrix with the vector (sort of like what a bsxfun(@times,matrix, vector) do if the vector is numeric). They should become a vector of n equations like 0.01*cake-0.5*sandwich+10*key (with no space and the '*' character included). I've been searching a lot, but with no proper knowledge of matlab I can't find anything. Noted the matrix is taken from a system of linear equations, but if I have to write them all back is would be fruitless since the matrix usually huge and there are many of them :(. And slxwrite them back into excel too. Please help me.
0 个评论
采纳的回答
jgg
2015-12-14
Something like this should do it:
A = magic(2);
c = cell(1,2);
c{1} = 'cat';
c{2} = 'winter';
out = cell(2,1);
for j = 1:2
str = '';
for i = 1:2
if i < 2
str = strcat(str,mat2str(A(j,i)),'*',c{i},'+');
else
str = strcat(str,mat2str(A(j,i)),'*',c{i});
end
end
out{j} = str;
end
You'll have to adjust the code a little bit so it works with your data, but basically just concatenate the strings.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!