How to perform a basic division to every x1000 data columns?
0 Kommentare
Akzeptierte Antwort
2 Kommentare
You're welcome!
Since result is a vector, you can simplify the NaN removal code as follows:
result = result(~ismissing(result));
Weitere Antworten (1)
Hi @Sara Woods ,
Let me addresss your query regarding, “I need to compute below half adaptation on each column (x1000) of spikes_std_mtx.mat over S.std.time but I don't know how to code it. I would like to save the x1000 results within a column”
Please see my response to your comments below.
First, I loaded the spike data from the spikes_std_mtx.mat file which is already provided in your posted comments. This file should contain a matrix where each column represents a different trial or condition. Then, create a variable to store the results for each column, specifically the time at which the spike count falls below half of the initial response. Afterwards, loop through each column, for each column in the matrix, I had to calculate the half of the initial spike count. Determine the time at which the spike count falls below this threshold and store the result in a pre-allocated results matrix. Finally, I had to make sure that if the spike count never falls below half of the initial response, I handled this gracefully (e.g., by storing NaN or a specific value).Here is the complete MATLAB code that implements the above logic:
% Load the spike data load('spikes_std_mtx.mat'); % Ensure this file contains the variable spikes_std_mtx % Assuming spikes_std_mtx is a matrix where rows are time points and columns are trials
% Initialize variables numTrials = size(spikes_std_mtx, 2); % Number of trials (columns) TimeForHalfAdaptation = NaN(numTrials, 1); % Pre-allocate results array
% Assuming S.std.time is defined and corresponds to the time points of spikes_std_mtx % Example: S.std.time = linspace(0, 5, size(spikes_std_mtx, 1)); % Adjust as necessary
for i = 1:numTrials % Calculate half of the initial spike count HalfIniFR = spikes_std_mtx(1, i) / 2;
% Find the time when spikes fall below half of the initial response belowHalfIdx = find(spikes_std_mtx(:, i) < HalfIniFR, 1, 'first'); % Get the first index below half if ~isempty(belowHalfIdx) TimeBelowHalfIniFR = S.std.time(belowHalfIdx); % Get the corresponding time else TimeBelowHalfIniFR = NaN; % If no spikes fall below half, store NaN end
% Store the result TimeForHalfAdaptation(i) = TimeBelowHalfIniFR; end
% Display the results disp('Time for half adaptation for each trial:'); disp(TimeForHalfAdaptation);
For more information on NaN function, please refer to
https://www.mathworks.com/help/matlab/ref/nan.html
Please see attached results.
So, you will see in the code that the load function imports your spike data from the specified .mat file to make sure that the variable spikes_std_mtx is correctly defined in the file. The TimeForHalfAdaptation array is initialized with NaN values to handle cases where the spike count does not fall below half. Then, for loop iterates through each trial (column) of the spike matrix and find function is used to locate the first occurrence where the spike count is less than half of the initial response. Afterwards, the results are stored in the TimeForHalfAdaptation array, which can be used for further analysis or visualization. Hope this helps answer your question.
2 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!