How to print cell contents into m-file?

1 回表示 (過去 30 日間)
Akbar
Akbar 2018 年 6 月 8 日
回答済み: Stephen23 2018 年 6 月 8 日
I Need to Combine These two variables and print in m-file. inputs and signs length may vary. signs can only contain multiplication and/or Division.
inputs = {'x' 'y' 'z' 'k'};
signs = '**/';
How to write the following line in m-file?
out = x*y*z/k;

採用された回答

Stephen23
Stephen23 2018 年 6 月 8 日
>> inputs = {'x' 'y' 'z' 'k'};
>> signs = '**/';
>> C = inputs;
>> C(2,1:end-1) = num2cell(signs);
>> fprintf('out = %s;\n',[C{1:end-1}])
out = x*y*z/k;

その他の回答 (1 件)

Jan
Jan 2018 年 6 月 8 日
inputs = {'x' 'y' 'z' 'k'};
signs = '**/';
Result = inputs{1};
for k = 1:numel(signs)
Result = [Result, signs(k), inputs{k+1}];
end
  1 件のコメント
Akbar
Akbar 2018 年 6 月 8 日
How to print it to the file? And without square brackets.

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

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by