How to Print Title According to Test Results

I'm writing this code and getting this error. Couldn't figure out the syntax error.
a=mean(z,1); % z is actually a data tabulated in 2400x62 matrix %
a1=hist(a,10);
h=chi2gof(a);
if h==0
h1=fprintf('Passed');
else h==1
h1=fprintf('Failed');
end
subplot(2,1,1);
stem(a);
xlabel('Signal - Column');
ylabel('Mean');
grid on;
subplot(2,1,2);
plot(a1);
title('Hypotheses Test- Result : %d','h1'); % <<< here the error is happening %
xlabel ('<---Distribution--->');
ylabel ('Value------>');
grid on;

 Accepted Answer

When MATLAB documentation says that a routine accepts Name, Value pairs, it means that the routine has defined a list of options that can be invoked by passing in a string that contains the name of the option, then a comma, then the value associated with the option. The documentation gives the example,
title('Case number # 3','Color', 'm')
Here the option name is 'Color' and the value associated with the option is 'm'.
Name, Value pairs are always pairs, option name and then value. There is never an option name given by itself. When an option is to be turned on but there is no particular associated value (like 'm' or 42), then the convention in MATLAB is that the associated value will be either 'on' or the numeric value 1 or the logical value true -- but MATLAB is not consistent as to whether 'on' or 1 is to be used. Roughly speaking, options that are on by default more often expect numeric 0 rather than 'off', whereas options that are off by default more often expect 'on' rather than 1 or true to activate them.
You are attempting to pass the option named 'h1' without an associated value. Option 'h1' is not on by default. You should therefore be using
title('Hypotheses Test- Result : %d','h1', 'on')
I presume that you must be using a pre-release (beta) version of MATLAB, as there is no documented option name 'h1' for title() in any released version
Note that title() are not represented in HTML, so the HTML "header 1" tag is not appropriate for title().

1 Comment

Walter, I have solved this problem. But 'Thanks' anyway.anyway. I have revised the code mentioned below.
a=mean(z,1);
a1=hist(a,10);
h=chi2gof(a);
if h==0
h1=sprintf('Passed');
else h=1;
h1=sprintf('Failed');
end
str = sprintf('Normal Distribution Test : %s',h1);<<%added this part
subplot(2,1,1);
stem(a);
xlabel('Signal - Column');
ylabel('Mean');
grid on;
subplot(2,1,2);
plot(a1);
title(str);
xlabel ('<---Distribution--->');
ylabel ('Value------>');
grid on;
Cheers and thanks again!!

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Objects in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!