simplest way to print equations

조회 수: 4 (최근 30일)
Standardtrickyness
Standardtrickyness 2015년 9월 14일
답변: Walter Roberson 2015년 9월 18일
given large A,b how to print the equations A(1,1) x_1 +A(1,2) x_2+..=b(1)
and preferably least amount of technicality?
  댓글 수: 2
Walter Roberson
Walter Roberson 2015년 9월 14일
print them to what output?
Is x_1 intended to indicate x subscript 1? As in you want literal 'x' and a subscript to appear?
Standardtrickyness
Standardtrickyness 2015년 9월 18일
yes I want literally 'x_1' just print them as strings are probably fine

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 9월 18일
part1 = arrayfun(@(col) strcat( cellstr(num2str(A(:,col))), sprintf(' x_%d', col) ), 1:size(A,2), 'Uniform', 0);
part2 = horzcat(part1{:});
part3 = arrayfun(@(row) strjoin(part2(row,:), ' + '), 1:size(A,1), 'Uniform', 0);
part4 = strcat(part3(:), {' = '}, cellstr(num2str(b(:)) ));
part4 is now a cell array of strings, one per row in A

제품

Community Treasure Hunt

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

Start Hunting!

Translated by