Create new variable with only values of a certain variable

2 ビュー (過去 30 日間)
Mary Hemler
Mary Hemler 2020 年 6 月 1 日
編集済み: Tommy 2020 年 6 月 1 日
I want to save a new variable 'highMI_sec' as only the values of mutualInfoTotal that are at least equal to 5 (at end of code). How can I do this?
for i = 1:n_cells
spikes = cellspikes{i}; % access cellspikes
spikes = spikes./1000; % ms to secs
spikes = spikes(spikes>startTime&spikes<stopTime);
edgesT = linspace(startTime,stopTime,numel(trackingtimes)+1);
binnedSpikes = histcounts(spikes,edgesT);% sorts spikes into bins
% also bin headangle data
n_bins_angle = 60;
edgesHD = linspace(min(headangle), max(headangle), n_bins_angle +1);
[occupancy,~,angle_inds] = histcounts(headangle,edgesHD);
for iBin = 1:n_bins_angle
spikesPerAngle(iBin) = sum(binnedSpikes(angle_inds == iBin));
end
SPA(1,i)={spikesPerAngle};
% compute average firing rate for each HD angle
firing_rate = spikesPerAngle./(occupancy.*deltaT); %this vector is a TUNING CURVE!
FR(1,i) = {firing_rate};
% now compute individual pieces needed to compute mutual info
probability_density = occupancy./sum(occupancy); %proportion of time spent at each HD angle per total occupancy at all angles
PD(1,i)={probability_density};
% compute average firing rate across all HD angles
mean_rate = numel(spikes)./(stopTime-startTime);
MR(1,i) = mean_rate;
% compute mutual info between firing rate and HD
mutualInfo = sum(firing_rate .* log2(firing_rate./mean_rate) .* probability_density,'omitnan');
MIperspike = mutualInfo./(mean_rate);
%store mutual info for each cell into a matrix
mutualInfoTotal(1,i) = mutualInfo; %in bits per second
MISpikeTotal(1,i) = MIperspike;
end

採用された回答

Tommy
Tommy 2020 年 6 月 1 日
Try this:
idx = mutualInfoTotal >= 5; % indices of values at least equal to 5
mutualInfoTotal = mutualInfoTotal(idx);
  2 件のコメント
Mary Hemler
Mary Hemler 2020 年 6 月 1 日
Okay, that worked, thanks. but the first statement didn't actually give me the indices of the values at least equal to 5 (it gave me a logical array). How can I find out the indices of the values at least equal to 5? I am trying to use that for my next step.
Tommy
Tommy 2020 年 6 月 1 日
編集済み: Tommy 2020 年 6 月 1 日
Happy to help!
True, that was poor wording on my part. You could use
idx = find(mutualInfoTotal >= 5);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by