Combine 3 array in one matrix of 3 columns
조회 수: 4 (최근 30일)
이전 댓글 표시
How can I combine these columns? I'm running this short program here:
clc
clear all
P(2)=2*sqrt(2);
for n=2:30
P(n+1)=2^n*sqrt(2*(1-sqrt(1-(P(n)/2^n)^2)));
errabs(n)=abs(pi-P(n));
end
P(31)=[];
Matrice=[2:30;P;errabs];
fprintf('%s %13s %31s\t \n','n','Pn','Erreur absolue');
But even if in the workspace I can see that they're all 30 columns long I can't concatenate them.
Can anyone help me on this one?
I ran this one this morning without any problems:
clc
fprintf('a)\n');
v=0;
for i=1:13
v(i)=factorial(i);
end
fprintf('v=\t')
fprintf('%d\t',v);
%partie b)
fprintf('\n\nb)\n');
s_n=0;
for i=1:13
s_n(i)=sqrt(2*pi*i)*(i/exp(1))^i;
end
fprintf('Lapproximation est de:\n');
fprintf('%f\t',s_n);
%c)
for i=1:13
errabs(i)=abs(v(i)-s_n(i));
errrel(i)=abs((v(i)-s_n(i))./v(i));
end
fprintf('\n\nb)\nLerreur absolue est de:\n');
fprintf('%f\t',errabs);
fprintf('\n');
fprintf('\nc)\nLerreur relative est de:\n');
fprintf('%f\t',errrel);
disp(' ');
disp(' ');
disp('d)');
Matrice=[1:13;errabs;errrel];
fprintf('\n%s %20s\t\t %20s','n','Erreur absolue','Erreur relative');
fprintf('\n %d\t %1.16e \t %1.16e\n\n \n',Matrice);
댓글 수: 0
답변 (1개)
Walter Roberson
2017년 1월 22일
Matrice = [(2:30).', P(:); errabs(:)];
However, 2:30 is only 29 entries not 30, so you are going to have problems.
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!