Counting outcomes of names (2024)

11 views (last 30 days)

Show older comments

Ruben Moreno on 12 May 2022

  • Link

    Direct link to this question

    https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names

  • Link

    Direct link to this question

    https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names

Commented: Ruben Moreno on 12 May 2022

Accepted Answer: Matt J

Hi, i have a collumn of names of investors in a large dataset and im trying to extract the occurance of every investor. A large quanitity have a combination of investors, meaning there are several names in one cell, so they would only be counted once if i were to count them alone. Is there any way to count all names, even in combination with others?

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Matt J on 12 May 2022

  • Link

    Direct link to this answer

    https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#answer_962585

  • Link

    Direct link to this answer

    https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#answer_962585

Edited: Matt J on 12 May 2022

Open in MATLAB Online

Something like this, perhaps?

investors=["Sam";"Joe";"Sam and Joe"]

investors = 3×1 string array

"Sam" "Joe" "Sam and Joe"

contains(investors,"Sam")

ans = 3×1 logical array

1 0 1

8 Comments

Show 6 older commentsHide 6 older comments

Ruben Moreno on 12 May 2022

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154550

In simple terms yes, but considering the magnitude of my data and the amount of investors, its not possible to simply write down all names. Added picture for visualization of the problem

Counting outcomes of names (4)

Ruben Moreno on 12 May 2022

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154645

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154645

because i want to count all investors in every combination in a data of 33,000 observations. in a total of 8132 unique investor cominations. I cant write the name of all of these investors to count how many there are?

Matt J on 12 May 2022

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154670

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154670

Edited: Matt J on 12 May 2022

Open in MATLAB Online

Why isn't my solution applicable? Is it that you don't hav a prior list of all the investors? If not, will multiple investors always be delimited by commas? If so, you can use strsplit:

investors=["Sam";"Joe";"TPG, Sam, Joe";"TPG, Joe"]

investors = 4×1 string array

"Sam" "Joe" "TPG, Sam, Joe" "TPG, Joe"

Names = cellfun(@(x)strsplit(x,{', '}), investors, 'UniformOutput', false);

Names=string(unique(horzcat(Names{:})'))

Names = 3×1 string array

"Joe" "Sam" "TPG"

count=nan(size(Names));

for i=1:numel(Names)

count(i)=sum(contains(investors,Names{i}));

end

table(Names,count)

ans = 3×2 table

Names count _____ _____ "Joe" 3 "Sam" 2 "TPG" 2

Ruben Moreno on 12 May 2022

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154715

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154715

thank you, will look into this, what does the UniformOutput do in this case?

Matt J on 12 May 2022

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154725

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154725

You're welcome, but if it does what you need, please Accept-click the answer.

UniformOutput=false forces the result of cellfun to be returnd as a cell array,

https://www.mathworks.com/help/matlab/ref/cellfun.html#d123e172702

Ruben Moreno on 12 May 2022

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154740

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154740

i get an error on the first line, Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other

syntax error. To construct matrices, use brackets instead of parentheses.

Matt J on 12 May 2022

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154765

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154765

The error is not coming from code that you've shown us (or that I've shown you).

Ruben Moreno on 12 May 2022

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154790

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154790

Nvm, i fixed it. It worked now, Wow. thank you very much!

Sign in to comment.

More Answers (1)

Stephen23 on 12 May 2022

  • Link

    Direct link to this answer

    https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#answer_962660

  • Link

    Direct link to this answer

    https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#answer_962660

Edited: Stephen23 on 12 May 2022

Open in MATLAB Online

str = ["Sam";"Joe";"TPG, Sam, Joe";"TPG, Joe"]

str = 4×1 string array

"Sam" "Joe" "TPG, Sam, Joe" "TPG, Joe"

spl = regexp(str,',','split');

[uni,~,idx] = unique(strtrim([spl{:}]));

cnt = histcounts(idx);

[uni;cnt]

ans = 2×3 string array

"Joe" "Sam" "TPG" "3" "2" "2"

1 Comment

Show -1 older commentsHide -1 older comments

Ruben Moreno on 12 May 2022

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154900

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/1717685-counting-outcomes-of-names#comment_2154900

i figured the problem out. But i have a follow up question, I want to use the information i gained. Count of every investors frequency. to add a indication for experience in the original dataset. Creating a dummy for investors observations > 100 and 0 for the rest.

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphicsFormatting and AnnotationLabels and AnnotationsAnnotations

Find more on Annotations in Help Center and File Exchange

Tags

  • text
  • frequency
  • count
  • combination

Products

  • MATLAB

Release

R2022a

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Counting outcomes of names (14)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • 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
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

Contact your local office

Counting outcomes of names (2024)
Top Articles
Latest Posts
Article information

Author: Geoffrey Lueilwitz

Last Updated:

Views: 5728

Rating: 5 / 5 (60 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Geoffrey Lueilwitz

Birthday: 1997-03-23

Address: 74183 Thomas Course, Port Micheal, OK 55446-1529

Phone: +13408645881558

Job: Global Representative

Hobby: Sailing, Vehicle restoration, Rowing, Ghost hunting, Scrapbooking, Rugby, Board sports

Introduction: My name is Geoffrey Lueilwitz, I am a zealous, encouraging, sparkling, enchanting, graceful, faithful, nice person who loves writing and wants to share my knowledge and understanding with you.