Error using fprintf , not defined for cell inputs

5 ビュー (過去 30 日間)
B T
B T 2012 年 9 月 1 日
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

回答 (2 件)

Walter Roberson
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}

Dishant Arora
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(:))

カテゴリ

Help Center および File ExchangeBiological and Health Sciences についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by