0

Hello, I am having problems with some text string errors in my code. Any help would be appreciated. Here is a snippet of my code.

clear all

value = input(['Please enter a positive real numerical ' ...
    'measurement of volume:']);

initial = input(['Please select a starting measurement unit' ...
    'from the following menu of choices \n' ...
    '(liter - l, gallon - gal, cubic feet - ft3, or bushels - bu):']);

final = input (['Please select an ending measurement unit' ...
    'from the following menu of choices \n' ...
    '(liter - l, gallon - gal, cubic feet - ft3, or bushels - bu):']);

[final_conversion] = conversion (initial, final, value);

if strcmp(initial, 'l') && strcmp(final, 'gal')
    disp ([num2str(value),' liters is equal to ' ...
        ,num2str(final_conversion), ' gallons.'])

If I run the program I am getting the following errors:

??? Error using ==> input
Undefined function or variable 'l'.

Error in ==> hw2 at 11
initial = input(['Please select a starting measurement unit' ...

Any guidance would be greatly appreciated!

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by jonsca
0

Disp and input should just take plain ol' strings. I'm not sure what you are trying to do with the [ ] but I don't believe it's correct. In the case on the last 2 lines you'll have to use something like sprintf to make a string out of the numerical values and the text and then display that string. I don't have a copy of Matlab to test it on but that's my recollection for the disp and input part.

Edited by jonsca: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.