Running the following code gives the classic "Dot indexing is not supported for variables of this type"

12 次查看(过去 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 CenterFile Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by