Resolving Matrix dimensions must agree

I am creating a unit converter app with app designer and I am having trouble with the following switch statement and getting the error - Matrix dimensions must agree.
The app should select between imperial and Metric conversion, and should swap units via a drop down box.
I tried using a switch case instead of an if/else statement but it also didn't recognise the case parameters.
The problem lies within my 'if' conditions, i.e. if app.DropDown.Value == char('Celsius to Fahrenheit') --- it either says Matrix dimensions must agree or it goes straight to my error message.
How do i get the code to read what units are in the drop down box and then run that code?

1 件のコメント

Stephen23
Stephen23 2021 年 5 月 6 日
Note that calling char on a character vector does nothing, it returns exactly the same char vector unchanged.

サインインしてコメントする。

回答 (1 件)

Stephen23
Stephen23 2021 年 5 月 6 日
編集済み: Stephen23 2021 年 5 月 6 日

1 投票

Use strcmp or strcmpi to check if two text strings match or not:
if strcmp(A,B)
Alternatively you could use one switch statement:
switch app.DropDown.value
case 'Celcius to Farenheit'
..
case 'etcetera'
..
otherwise
error('Oh No, I don''t know what to do with this!')
end

1 件のコメント

Hannah Quirk
Hannah Quirk 2021 年 5 月 7 日
I decided to use the if strcmp(A,B) format, and it worked!
Thank you for this.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

質問済み:

2021 年 5 月 6 日

コメント済み:

2021 年 5 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by