Cant index into a constant Property of a class
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to index into a string array, that is stored into the property of a constants class i created. When i get to the line of code (below) where the call is made, it returns the entire array. But when i insert that line of code into the command window, it runs just fine.
if Data.isCellOpen(Constants.CellNames(1), index)
댓글 수: 0
답변 (1개)
Prince Kumar
2022년 1월 21일
Hi,
You can index into string array just like normal indexing. Please look at the code below for reference:
classdef NamedConst
properties (Constant)
R = pi/180
D = 1/NamedConst.R
AccCode = '0145968740001110202NPQ'
str = ["Mercury" "Gemini" "Apollo";
"Skylab" "Skylab B" "ISS"]
end
end
Now you can use the class name NamedConst to access the property and index it.
disp(NamedConst.str(1))
This "disp" function gives Mercury as output.
For more information please refer the the documentation : Defining Class Properties with Constant Values
Hope this helps!
댓글 수: 3
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!