Is there a way I can assign values to a vector of names?
조회 수: 1 (최근 30일)
이전 댓글 표시
I want to have a vector of names, and use a for loop to give a value to each name.
For example, the bcvalues = {'bar01','bar01382,....}
for i = 1:length(bcvalues)
bcvalues(i) = NaN(1,30);
end
However, I obtained a "Conversion to cell from double is not possible."
Any kind of help is appreciated. Thank you.
댓글 수: 1
Ravi Narasimhan
2021년 9월 8일
편집: Ravi Narasimhan
2021년 9월 8일
Matlab also allows "Associative Arrays" (e.g. dictionaries in Python) that can allow key/value pairs to be established.
You can look up containers.Map at:https://www.mathworks.com/help/matlab/matlab_prog/overview-of-the-map-data-structure.html
% Define the keys
S={'bar01','bar01382'}
% Map the keys to values; NaN(1,30) for the first and 2:10 for the second
mapObj = containers.Map(S,{nan(1,30), [2:10]})
% Examine the values of the object using the keys
mapObj('bar01')
mapObj('bar01382')
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!