필터 지우기
필터 지우기

How to print cell contents into m-file?

조회 수: 2 (최근 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 CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by