Error using fprintf , not defined for cell inputs

1 Ansicht (letzte 30 Tage)
B T
B T am 1 Sep. 2012
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

Antworten (2)

Walter Roberson
Walter Roberson am 1 Sep. 2012
Bearbeitet: Walter Roberson am 1 Sep. 2012
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}

Dishant Arora
Dishant Arora am 1 Sep. 2012
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(:))

Kategorien

Mehr zu Function Creation 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!

Translated by