Just a quick question so i have:
[x,y]
ans =
0.1771 0.1822
0.8296 0.0991
0.7669 0.4898
0.9345 0.1932
0.1079 0.8959
How do i assign this to have for example:
c1 = (0.1771,0.1822)
c2 = (0.8296,0.09910
c3 = (0.7669,0.4898)
...
until all values are assigned an 'id'
Thank you

댓글 수: 2

Rik
Rik 2021년 3월 25일
You should not do that. There are exceedingly few situations where numbered variables are a better choice than an array. A longer discussion can be found here.
An array can be indexed, while you would have to regenerate the variable every time you wanted to use it.
What is you want to achieve? We might be able to give you advice about what you could use instead.
Samuel Shlong
Samuel Shlong 2021년 3월 25일
ok ill look in to that
thanks

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

 채택된 답변

Cris LaPierre
Cris LaPierre 2021년 3월 26일
편집: Cris LaPierre 2021년 3월 26일

0 개 추천

A solution really depends on what you are trying to achieve. If you want to use c1, c2, etc to refer to a row of values, consider a table with rownames.
x = [0.1771; 0.8296; 0.7669; 0.9345; 0.1079];
y = [0.1822; 0.0991; 0.4898; 0.1932; 0.8959];
A = table(x,y,'RowNames',"c"+(1:length(x)))
A = 5×2 table
x y ______ ______ c1 0.1771 0.1822 c2 0.8296 0.0991 c3 0.7669 0.4898 c4 0.9345 0.1932 c5 0.1079 0.8959
A{'c2',:}
ans = 1×2
0.8296 0.0991
Another option is to use c1, c2, etc as your variable names in the table.
B = array2table([x,y]','VariableNames',"c"+(1:length(x)))
B = 2×5 table
c1 c2 c3 c4 c5 ______ ______ ______ ______ ______ 0.1771 0.8296 0.7669 0.9345 0.1079 0.1822 0.0991 0.4898 0.1932 0.8959
B.c3
ans = 2×1
0.7669 0.4898
You can learn more about accessing data in a table here.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2019b

태그

질문:

2021년 3월 25일

편집:

2021년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by