필터 지우기
필터 지우기

STRCAT SYNTAX TO BE USED?

조회 수: 3 (최근 30일)
ck
ck 2016년 5월 7일
편집: Jan 2016년 5월 7일
IF I WANT TO STRCAT 2 VALUES I WOULD DO STRCAT(S1,S2), SO WHAT IF I WANT TO DO N VALUES AND 'N' IS A VALUE WHICH GETS DEFINED IN BETWEEN THE PROGRAM?? WHAT IS THE SYNTAX I SHOULD USE?
THANK YOU
  댓글 수: 1
Jan
Jan 2016년 5월 7일
Please note that writing in uppercase means shouting in the forum. So please calm down and type your question as all otehr do with a proper case. Thanks.

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 7일
N=3
str='abc'
out=repmat(str,1,N)

추가 답변 (1개)

Jan
Jan 2016년 5월 7일
편집: Jan 2016년 5월 7일
If you store a dynamical number of string, you do not use the names S1, S2, S..., but you store them in a cell string:
C = {'String 1', 'String 2', 'String 3'}; % and so on
Then instead of writing:
S = strcat(C{1}, C{2}, C{3})
You can write:
S = strcat(C{:});
This works with 200 million strings also, where names like S200000000 would be too ugly.
  댓글 수: 2
ck
ck 2016년 5월 7일
thanks!, so if I want to strcat the elements on matrix from a(1,1) to a(n,1) into another matrix b(1,1) how is that done?
Jan
Jan 2016년 5월 7일
편집: Jan 2016년 5월 7일
@Chetan: You have selected Azzi's answer as a solution, but it performs something completely different. Accepting an answer means, that it solves your problem.
You cannot assign a vector with many elements to a scalar variable b. Storing strings in a CHAR-matrix has severe disadvantages, e.g. you cannot distinguish the padded spaces with trailing spaces, which belong to the strings. A conversion to a cell string removes the padded spaces:
S = char('hi', 'matlab', 'user');
C = cellstr(S);
B = strcat(C{:})
If you want to keep the spaces you do not need strcat:
B = reshape(S.', 1, [])

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by