How to sum two different variables?

12 ビュー (過去 30 日間)
Estudante Matlab
Estudante Matlab 2016 年 5 月 28 日
回答済み: Image Analyst 2016 年 5 月 28 日
I wrote the below code:
B = input('Type the value of B: ');
C = input('Type the value of C: ');
E = input('Type the value of E: ');
F = input('Type the value of F: ');
A = (B - C).^3;
D = (E - F).^3;
K = (A + D)
Is there a way to sum A + D in a single line? I mean:
[A, D] = ((B - C).^3 + (E - F).^3);
Thanks!!!

回答 (1 件)

Image Analyst
Image Analyst 2016 年 5 月 28 日
I don't know why being in a single line is so important, especially since it makes it more confusing, but if you insist for some reason, you can use deal():
[A, D] = deal((B - C).^3, (E - F).^3)
It assigns (B - C).^3 to A, and (E - F).^3 to D. It does not sum them together, so you still need to do
K = (A + D)

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by