0

I would like to know if how I'm plotting my data is an efficient way to go about it. Is this the case? Or does a different way exist, where I create the Structs and then create the plots outside of the for-loop in one go?

What I do:

Multiple plots per day per Rats. And I check for arrays which are not filled with zeroes, those arrays are not interesting. I have the values stored in a nested struct, which I build as follows:

for Rat = vecRat(1):vecRat(end)   
    for Day = UserDayArray 
        % I Build an array with Timediff here, which I left out for clarity
        Subject(Rat).day(Day). Timediff = Timediff;
        if isempty(Subject(Rat).day(Day).CumTimediff) == 0 && max((Subject(Rat).day(Day).CumTimediff)) ~= 0 && min((Subject(Rat).day(Day).CumTimediff)) ~=0
           stem(Subject(Rat).day(Day). Timediff)   %plots data
           end

        %Tells User that for this day no shaped trials were found.
        elseif isempty(Subject(Rat).day(Day).CumTimediff) == 0              
        fprintf(['****************** TSBP ', num2str(Rat), ' Day ', num2str(Day),'******************\n']);
        fprintf('No Shaping algorythm present/No Timechange detected\n');
        fprintf('No plots made\n');
        end
    end
end
4

1 回答 1

1

结合“cellfun”、逻辑索引和结构取消引用,这就是我想出的。不知道您的确切数据结构,但这应该可行。

alldays=Subject(vecRat(1):vecRat(end)).day
AllCumTimediff={alldays(UserDayArray).CumTimediff}
%Use nested cellfun using the all and eq functions to check which plots can be made
%all([])=true so check for isempty to
plotsNotToUse=cellfun(@all,cellfun(@eq,AllCumTimediff,repmat({0},1,numel(AllCumTimediff)),'UniformOutput',false))
%Call your plotter and message functions
cellfun(@myplotter,AllCumTimediff(~plotsNotToUse))
cellfun(@myemptyMessage,AllCumTimediff(plotsNotToUse))


%%
function myplotter(CumTimediff)
figure; % create new figure
plot(CumTimediff);
%Whatever other commands
于 2013-03-06T20:37:27.787 回答