Running the following code gives the classic "Dot indexing is not supported for variables of this type"
조회 수: 1 (최근 30일)
이전 댓글 표시
Hey all! So I'm currently running a piece of code which essentially retrieves all the trials ("myTrials") for a particular condition (referred in code as "condId") in a number of files (I'm currently loading them through a loop). I have written a function in a separate file, which on execution runs this following line of code. Note that the error occurs in this particular line.
myTrials = d.getConds()
which calls the respective function on another script. The complete script is shown as follows:
function [conds,condIds] = getConds(d)
% Retrieves all trials for a given condID
condIds = d.meta.condIds;
[~,ix] = unique(condIds);
tmp = d.meta.image.filename('time',Inf).data;
conds = {};
conds(ix) = tmp(ix);
myTrials = find(condIds == 1); %match all trials with conditionID = 1
end
댓글 수: 0
채택된 답변
Walter Roberson
2021년 4월 26일
편집: Walter Roberson
2021년 4월 26일
myTrials = d.getConds()
for this to work, d can be a struct with a field named getConds that happens to be a function handle. Notice that no parameter is passed to the handle.
function [conds,condIds] = getConds(d)
But notice this requires d to be passed in, which the struct/handle possibility would not do.
So d cannot be struct.
The alternative is that d could be an object of a class, and getConds could be a method declared for the class. This is legal, under the constraints described at https://www.mathworks.com/help/matlab/matlab_oop/methods-in-separate-files.html
It is not clear from what you have written that you have implemented a class.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!