Running the following code gives the classic "Dot indexing is not supported for variables of this type"
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Kevin Akash Rajasekaran
am 26 Apr. 2021
Bearbeitet: Walter Roberson
am 26 Apr. 2021
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 26 Apr. 2021
Bearbeitet: Walter Roberson
am 26 Apr. 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.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!