Create a logical vector
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi All,
I have a cell array, where each cell in the first row contains a double of various lengths. Each double corresponds to sample numbers where a spike occurs (from a neuron - variable called cluster_split). I also have created an array of 0's the length of signal I am interested in (variable called LFP). I would like to index across each double (i.e.: cluster_split{1,1}) and create a logical vector of 1's and 0's.
For example, if in cluster_split{1,1} there is a value equal to 2502 (corresponding to sample 2502 in the LFP vector), then Matlab would output a 1 to the LFP array. I would like to create a separate "LFP" file for every double in the cluster_split cell array.
Thanks in advance for the help!
PK
채택된 답변
1 개 추천
Does this help?
LFP = false(1, 3000);
LFP(2500) = true;
If LFP is at millisecond resolution and a spike occurs at 2500 milliseconds, you'll see a 1 in position 2500. Since I used true/false the vector is logical.
댓글 수: 9
Hi!
Thanks for your comment. That works in the case of just adding a "1" to position 2500 in LFP. However, what I'm looking to do is slightly different. I'll try to explain better below:
LFP is a 1 x 3000 matrix of 0s. The other matrix (cluster_class) has basically a 5000 x 1 list of sample numbers. I would like to basically return a "1" in LFP for every sample that is in cluster_class. So, for example, if in row 3000 of cluster_class, the value is "2321" that means that there should be a "1" in column "2321" of the LFP array.
Does that make sense? Sorry if I'm explaining it poorly.
Thanks!
Adam Danz
2018년 8월 2일
That's clearer and if I understand you correctly, you could use my example above to solve this problem. I created fake data so we have something to work with. If the fake data do not match your formats, please clarify.
cluster_class are random integers so there will be repeats.
LFP = false(1,3000);
cluster_class = randi(3000, 5000, 1);
To assign a 1 in LFP at the indices listed in cluster_class,
LFP(cluster_class) = true;
Note that this is the same as my answer above except we're using your variable. Also note that since I've used true/false, LFP will be a logical vector.
PAK
2018년 8월 2일
Hi! This is perfect and works with the code you provided.
One question though:
If cluster_class is a cell array, where each cell contains the sample numbers in an array (i.e.: cluster_class{1,1}, cluster_class{1,2}, cluster_class{1,n} etc) is it possible to still use this? I've added your code into a for loop over the variable "n". I've pasted it below (in this code, clusters = n).
Thank you!!
for i = clusters
% round spikeTimes to the nearest .5 millisecond
spxtime_round = round(spikeTimes*2)/2;
% convert spikeTimes to seconds; then convert to sample number
spxtime_samples = (spxtime_round/1000) * sr;
% create an array
cluster_class_samples = [spikeClusters spxtime_samples];
% separates essentially cluster x samples; each column in cluster_split{i} is the same cluster
temp = cluster_class_samples(:,1) == i;
cluster_split{i} = cluster_class_samples(temp,2);
% create a blank array of 0's the size of the LFP timeseries; each column is a cluster
test = size(data,2);
LFP = false(1, test);
LFP(cluster_split{i}) = true;
end
You did mention that cluster_class was a cell array and I missed that. Here's the same code for the cell array.
LFP = false(1,3000);
cluster_class = num2cell(randi(3000, 5000, 1));
LFP([cluster_class{:}]) = true;
If you're doing this in a loop,
LFP(cluster_class{i}) = true;
About your loop, there are some issues. For example, why are the first three lines executed in your loop when none of their results will change within the loop? Your 'test', 'LFP' variables will be overwritten at each iteration. From the looks of it, you don't need a loop at all.
Guillaume
2018년 8월 2일
If cluster_class is a cell array of scalar values, then it shouldn't be. It should be a vector, which will be easier to work with, use much much less memory (150 times less) and will be faster to process.
PAK
2018년 8월 3일
Hi,
You're right, I didn't even think about that. I took the first 3 lines out of the for loop. The below code works (I modified the LFP logical to have one row for each of the arrays in the cluster_class cell array). However, it seems to overwrite within each iteration of the for loop. Is there an easy way to prevent this?
Thanks!
PK
% get the size (in a scalar value) of the LFP vector
test = size(data,2);
% run through each of the arrays in the cluster_class cell array
for i = clusters % the cluster # corresponds to the cell array columns
LFP = false(i, test);
LFP(cluster_class{i}) = true;
end
PAK
2018년 8월 3일
Cluster_class is a cell array, with each column in the first row containing another array. Does your comment still apply? Thanks! PK
Does each array cluster_class{n} have the same size? In other words, are all cell arrays stored in cluster_class the same length? If so, this code can be simplified.
In any case, what is the value of 'clusters'? I think what you want is something like this
LFP = false(length(cluster_class), test);
for i = 1:length(cluster_class)
LFP(cluster_class{i}) = true;
end
PAK
2018년 8월 3일
Hi Adam,
Each array is not the same size. The value of 'clusters' is [1,2,3,4,5,6,7,8]. Essentially the row length of cluster_class{n}. The following code below works!
LFP_size = size(data,2);
for i = clusters
LFP(i, :) = false(1, LFP_size);
LFP(i,cluster_split_recalled_samples{i}) = true;
end
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
