필터 지우기
필터 지우기

Matlab: array of strings

조회 수: 1 (최근 30일)
marianoc84
marianoc84 2011년 10월 17일
Inside a Matlab function I need something like (as you can imagine in real life it should be represented as a for loop):
var(1) = 'First string';
var(2) = 'Second string';
...
var(i) = 'i-th string';
Alas, I can't do this cause var(1) should contain just a character (not an entire string) and I get:
??? Subscripted assignment dimension mismatch.
I've searching on the web, but I can't find a good solution, any ideas?
  댓글 수: 1
Jan
Jan 2011년 10월 17일
Then you search procedure was inefficient. The first 3 pages found by asking Google for "Matlab list of strings" contain the necessary information, that this is called "cell string" in Matlab. "docsearch strings" find good explanations in the local docs of Matlab.

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

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 10월 17일
Use cell array of strings:
var{1} = 'First string';
var{2} = 'Second string';
  댓글 수: 3
Sean de Wolski
Sean de Wolski 2011년 10월 17일
var{2} = 'Second string';
var{1} = 'First string';
Switch 'em to dynamically preallocate!
Fangjun Jiang
Fangjun Jiang 2011년 10월 17일
@Sean, that's a neat trick!

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

카테고리

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