필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Extracting the values from a cellarray

조회 수: 1 (최근 30일)
Reshma Ravi
Reshma Ravi 2017년 6월 12일
마감: MATLAB Answer Bot 2021년 8월 20일
I have a cellarray that is 'GUUA' [2] 'UUAG' [2] 'UAGC' [2] 'CGCC' [2] then my problem is to find the probability (individual item/total count, here p(GUUA)=2/8)of occurence. How is this possible.
Thanks in advance.

답변 (1개)

Michael Byrne
Michael Byrne 2017년 8월 4일
편집: Michael Byrne 2017년 8월 4일
One way to accomplish this is to use the contains function to get a logical array describing the locations of a specific string (in your example, 'GUUA'), and then summing this array to obtain the number of occurrences of this string. The number of occurrences can then be divided by the length of the cell array to obtain the probability:
c = {'GUUA','GUUA','UUAG','UUAG',...
'UAGC','UAGC','CGCC','CGCC'}; % Your cell array
p = sum(contains(c,'GUUA'))/length(c); % Probability
  댓글 수: 1
Akira Agata
Akira Agata 2017년 8월 4일
Just a minor comment. If you want to count 'GUUA' exactly, I would recommend using strcmp, like:
p2 = sum(strcmp(c,'GUUA'))/length(c);

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by