convert string to cell

조회 수: 12 (최근 30일)
Prakhar Modi
Prakhar Modi 2019년 12월 29일
댓글: Prakhar Modi 2019년 12월 29일
hello everyone,
I have been genrating an equation using some parameters and I have been writing it as below:
equation{a}=[Parameters(a) "=" a0 "+" a1 "+" a2];
now, this is giving me 1x1 cell in which I get 1x7 string. Now what is really want is that is it possible to convert this in a way that when I write the equation in excel it can be written in one cell only as a whole equation. Because as I am running it with loop so I have to make correction in excel which take a lot of time.
Thanks in advance

채택된 답변

Stephen23
Stephen23 2019년 12월 29일
If the inputs are scalar strings use + to append them together:
equation{a} = Parameters(a) + "=" + a0 + "+" + a1 + "+" + a2;
If the inputs are character vectors you can concatenate them using []:
equation{a} = [Parameters(a),'=',a0,'+',a1,'+',a2];
But I would recommend using sprintf, which works with both:
equation{a} = sprintf('%s=%s+%s+s%',Parameters(a),a0,a1,a2);
  댓글 수: 1
Prakhar Modi
Prakhar Modi 2019년 12월 29일
thanks man it worked

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by