Continuing an input function onto another line

I was wondering how I could continue the following function onto another line. It's quite lengthy so I would like to move it to another line and make it look cleaner.
val = input('Type C for Celsius to Fahrenheit or Type F for Fahrenheit to Celsius or Type K for Celsius to Kelvin: ','s');
I tired using ellipses (...), but something wasn't working and I was getting a reading saying I might be missing an extra parenthesis.

1 件のコメント

per isakson
per isakson 2020 年 5 月 17 日
"using ellipses (...), but something wasn't working" Tell us what exactly didn't work, the full statement including the continuation lines together with the complete error message.
I use ellipses all the time without having any problems.

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

回答 (2 件)

per isakson
per isakson 2020 年 5 月 17 日
編集済み: per isakson 2020 年 5 月 17 日

0 投票

The documentation says;
The start and end quotation marks for a character vector must appear on the same line. For example, this code returns an error, because each line contains only one quotation mark:
mytext = 'Accelerating the pace of ...
engineering and science'
Replace
val = input('Type C for Celsius to Fahrenheit or Type F for Fahrenheit to Celsius or Type K for Celsius to Kelvin: ','s');
by
val = input(['Type C for Celsius to Fahrenheit or Type F for Fahrenheit ' ...
, 'to Celsius or Type K for Celsius to Kelvin: '], 's' );
Steven Lord
Steven Lord 2020 年 5 月 18 日

0 投票

I would use string arrays if you're using a release that supports them.
s = input("Enter C to convert Celcius to Fahrenheit" + newline + ...
"Enter F to convert Fahrenheit to Celcius" + newline + ...
"Enter K to convert Kelvin to Celcius" + newline + ...
"Enter your choice here: ", "s")

1 件のコメント

Carter Kunert
Carter Kunert 2020 年 5 月 18 日
What if my line includes num2str?
fprintf([ 'The Original Temperature in Fahrenheit is ' num2str(Fahrenheit) '.' '\n' 'The Converted Temperature in Celcius is ' num2str(Fahrenheit2Celsius(Fahrenheit)) '.']);

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

カテゴリ

ヘルプ センター および File ExchangeText Data Preparation についてさらに検索

タグ

質問済み:

2020 年 5 月 17 日

コメント済み:

2020 年 5 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by