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

採用された回答

Walter Roberson
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 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by