필터 지우기
필터 지우기

from string array to variable names

조회 수: 16 (최근 30일)
Meh
Meh 2012년 3월 29일
Hallo, I have a string array, say array A which has elements like A1 A2 A3 And I want to change them to variable names so that I can create another array based on these names. For example: for i=1:n A(i,1)= [X(i,1),Y(i,1)] end where X and Y are other arrays.

답변 (2개)

Matt Kindig
Matt Kindig 2012년 3월 29일
You can use genvarname to generate variable names.
doc genvarname
However, you probably don't want to actually do this. MATLAB recommends against making variables like A1, A2, etc. See below for suggested workarounds.
  댓글 수: 1
Meh
Meh 2012년 3월 29일
Thank you Matt,
but the above string matrix was just as an example. the actual elements look like AIW30 BWK90 SW94 . Do you think that the genvarname can stil give me the variables?

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


Jan
Jan 2012년 3월 29일
Using strings as variable names works with eval. But care for the FAQ link Matt has posted. Creating variables dynamically is a bad programming style, prone to errors, nearly impossible to debug and it slows down Matlab substantially.

카테고리

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