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 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tien Phat Ngo Nguyen
am 14 Dez. 2015
Kommentiert: Tien Phat Ngo Nguyen
am 15 Dez. 2015
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 Kommentare
Akzeptierte Antwort
jgg
am 14 Dez. 2015
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!