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 ?
2 ビュー (過去 30 日間)
古いコメントを表示
Tien Phat Ngo Nguyen
2015 年 12 月 14 日
コメント済み: Tien Phat Ngo Nguyen
2015 年 12 月 15 日
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 で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!