I am having some issues trying to get this code to function properly. It is supposed to help me formulate categorical logic statements quickly. I am assigning the varibles to the strings properly? All varibles should have the string as:
varible = input('Prompt: ', 's')
But I am still getting this error:
"Matrix dimensions must agree"
Here is my code.
%Categorical Syllogisms%
%Enter the categorical syllogism's part in standard form.%
disp('Enter the categorical syllogism parts in standard form.')
disp('Use all lowercase when entering your terms.')
quant = input('Quantifier: ','s');
if isempty(quant)
disp('Error, no quantifier entered.')
end
subject_term = input('Subject Term: ','s');
if isempty(subject_term)
disp('Error, no subject term entered.')
end
copula = input('Copula: ','s');
if isempty(copula)
disp('Error, no copula entered.')
end
predicate = input('Predicate Term: ','s');
if isempty(predicate)
disp('Error, no predicate entered')
end
%Categorical Proposition Type%
if quant == 'all'
if copula == 'are'
disp('Type A statement.')
disp('Quantity/Quality: Universal/Affirmative')
statement = 'A';
else
disp('Invalid copula entered.')
end
if quant == 'no'
if copula == 'are'
disp('Type E statement.')
disp('Quantity/Quality: Universal/Negative')
statement = 'E';
else
disp('Invalid copula entered.')
end
if quant == 'some'
if copula == 'are'
disp('Type I statement.')
disp('Quantity/Quality: Particular/Affirmative')
statement = 'I';
if copula == 'are not'
disp('Type O statement.')
disp('Quantity/Quality: Particular/Negative')
statement = 'O';
else
disp('Invalid copula entered.')
end
end
else
disp('Invalid quantifier entered.')
end
end
end

 Réponse acceptée

try
'no' == 'all'
catch ME
disp(ME.message)
end
Matrix dimensions must agree.
'no' is a char row vector with two elements. 'all' is a char row vector with three elements. You can't compare a row vector with two elements and a row vector with three elements using ==. Use strcmp or matches instead.
if strcmp('no', 'all')
disp('Match')
else
disp('No match')
end
No match
if strcmp('all', 'all')
disp('Match')
else
disp('No match')
end
Match
doesMatch1 = matches('no', 'all')
doesMatch1 = logical
0
doesMatch2 = matches('all', 'all')
doesMatch2 = logical
1
Or since you have a small finite list of allowed values, you could use switch and case.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by