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

1 visualización (últimos 30 días)
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 26 de Abr. de 2021
Editada: Walter Roberson el 26 de Abr. de 2021
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.

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by