Error using fprintf , not defined for cell inputs
조회 수: 5 (최근 30일)
이전 댓글 표시
I have a trivial bug that has me stumped.
t=[0:30];
%Infection
I=0.05*exp(-t);
%Loosening
L=0.01*exp(0.15*t);
%Fracture
F=0.01*exp(0.01*t);
%Wear
W=0.01*exp(0.1*t);
%Surgical Error
SE=0.001;
%Pain
P=0.005;
B={'Infection', 'Looseness',' Fracture', 'Wear', 'Surgical Error', 'Pain'};
A= B(1), B(4);
I(15),W(15);
I(30),W(30);
B(2), B(5);
L(15),SE;
L(30),SE;
B(3), B(6);
F(15),P;
F(30),P;
fS='Probability of Failure for %s is %4.2e after 15 years and %4.2e after 30 years\n';
fprintf(fS,A)
----
This results in ...
??? Error using ==> fprintf
Function is not defined for 'cell' inputs.
Error in ==> HW1 at 61
fprintf(fS,A)
My intent is to have something like :
Probability of Failure for _'Infection/looseness/etc...'_ is _'### for each category'_ after 15 years and _'### for each category'_ after 30 years\n'
----
I attempted fprintf(fS,A{:}), but when I do this the text do not display properly and it does not display the entire matrix
Thank you for any help on this
댓글 수: 0
답변 (2개)
Walter Roberson
2012년 9월 1일
편집: Walter Roberson
2012년 9월 1일
The code you give assigns only B(1) to A. The B(4), I(15), W(15) and so on, will either be displayed to the user or simply discarded.
Perhaps you want
A= { B{1}, B{4}; ...
I(15), W(15); ...
I(30), W(30); ...
B{2}, B{5}; ...
L(15), SE; ...
L(30), SE; ...
B{3}, B{6}; ...
F(15), P; ...
F(30), P };
Note that I changed B(1) to B{1}
댓글 수: 0
Dishant Arora
2012년 9월 1일
t=[0:30];
%Infection
I=0.05*exp(-t);
%Loosening
L=0.01*exp(0.15*t);
%Fracture
F=0.01*exp(0.01*t);
%Wear
W=0.01*exp(0.1*t);
%Surgical Error
SE=0.001;
%Pain
P=0.005;
B={'Infection', 'Looseness',' Fracture',...
'Wear', 'Surgical Error', 'Pain'};
A=[I(15),I(30);L(15),L(30);F(15),F(30);W(15),W(30);SE,SE;P, P];
fS='Probability of Failure for %s%s%s%s%s%s is %4.2e%4.2e%4.2e%4.2e%4.2e%4.2e after 15 years and %4.2e%4.2e%4.2e%4.2e%4.2e%4.2e after 30 years\n';
fprintf(fS,B{1},B{2},B{3},B{4},B{5},B{6},A(:))
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Biological and Health Sciences에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!