How to get answer from this else if code

1 Ansicht (letzte 30 Tage)
Fateme Jalali
Fateme Jalali am 7 Mär. 2016
Bearbeitet: Walter Roberson am 7 Mär. 2016
Hello.I wrote matlab code below. when I change value of parameter num_modes to 5 or 6, the answer should be 'result2:graphic or <text> block' or two next conditions in program.But for every values of num_modes my code shows one of first two if results.can any one help me to correct my codes?
clc;
clear all;
close all;
%calculate comulative probibility
num_modes=5
matrix_comulative_probibility(1)=1.5;
matrix_comulative_probibility(2)=0.562;
matrix_comulative_probibility(3)=1.5;
matrix_comulative_probibility(4)=0;
T1=0.3;
T2=128;
T3=70;
%if num_modes==0
%disp('result2:smooth block or background')
if num_modes==1&&matrix_comulative_probibility(1)>T1;
disp('result2:background block');
elseif 1<num_modes<=3&&matrix_comulative_probibility(1)+matrix_comulative_probibility(2)>T1&&0<=abs(matrix_comulative_probibility(1)-matrix_comulative_probibility(2))<=1.5;
disp('result2:text block');
elseif num_modes<=4&&matrix_comulative_probibility(1)+matrix_comulative_probibility(2)+matrix_comulative_probibility(3)+matrix_comulative_probibility(4)>T1;
disp('result2:graphic or <text> block');
elseif num_modes>4&&matrix_comulative_probibility(1)+matrix_comulative_probibility(2)+matrix_comulative_probibility(3)+matrix_comulative_probibility(4)<T3;
disp('result2:image block');
else
disp('result2:undetected <image> block');
end

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 7 Mär. 2016
Bearbeitet: Walter Roberson am 7 Mär. 2016
1<num_modes<=3 means ((1<num_modes)<=3) . The (1<num_modes) part will return either 0 (false) or 1 (true), and 0 and 1 are both <=3 so the condition will always be true.
You need
1 < num_modes && num_modes <= 3

Weitere Antworten (0)

Kategorien

Mehr zu Dialog Boxes finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by