Hi all,
I have a program that will solve a linear system with any amount of rows and columns. I am displaying the solution to the sytem, which is answered in a row vector form.
Currently my answer is formatted as, disp(X):
1
1
When I would like the program to format it as
x1 = 1
x2 = 1
I am not sure how to display the specific row answer.
Thanks for the help!

댓글 수: 2

Image Analyst
Image Analyst 2018년 11월 30일
Is X a row vector or a 2-D Matrix? What is x1 and x2? Are those X(1,:) and X(:, 2) - the rows of matrix X? Why do you get 1 and 1 the first time and 1 and 2 the second time?
Jacob Varnell
Jacob Varnell 2018년 11월 30일
Sorry about the different answers 1 and 2, that was a mistake on my part, they should be the same. x1 and x2 are the rows of Matrix X. Matrix X are the solutions to the system.

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

 채택된 답변

KSSV
KSSV 2018년 11월 30일

0 개 추천

x = rand(10,1) ;
for i = 1:length(x)
fprintf('x%s = %f\n',num2str(i),x(i)) ;
end

추가 답변 (1개)

TADA
TADA 2018년 11월 30일

0 개 추천

arrayfun(@(x, i) disp(['x' num2str(i) ' = ' num2str(x)]),x,(1:numel(x))')

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2018년 11월 30일

댓글:

2018년 11월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by