Extracting text frequency to compare large datasets

Please can you help me to extract the frequency at which each port receives each gear type. The data set is huge, so I need MATLAB to read through and give results for the frequency of Appledoor "Pots and Traps", for example, so that can then be compared with Appledoor "Demersal trawl/seine" or Arbroath "Pots and traps" if needed. They are currently in two columns in an Excel workbook.
Port of Landing Gear Category
Appledore Pots and traps
Appledore Pots and traps
Arbroath Demersal trawl/seine
Arbroath Pots and traps
Arbroath Pots and traps
Arbroath Demersal trawl/seine
Ardglass Demersal trawl/seine
Ardglass Demersal trawl/seine
Ardglass Demersal trawl/seine
Ardglass Pots and traps
Ardglass Pots and traps
Aberdaran Pots and traps
Aberdaran Pots and traps
Aberdeen Pots and traps

1 Comment

Make it easy for people to help by attaching an Excel workbook.

Sign in to comment.

Answers (1)

Try histogram2():
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 20;
ca = {...
'Appledore' 'Pots and traps'; ...
'Appledore' 'Pots and traps'; ...
'Arbroath' 'Demersal trawl/seine'; ...
'Arbroath' 'Pots and traps'; ...
'Arbroath' 'Pots and traps'; ...
'Arbroath' 'Demersal trawl/seine'; ...
'Ardglass' 'Demersal trawl/seine'; ...
'Ardglass' 'Demersal trawl/seine'; ...
'Ardglass' 'Demersal trawl/seine'; ...
'Ardglass' 'Pots and traps'; ...
'Ardglass' 'Pots and traps'; ...
'Aberdaran' 'Pots and traps'; ...
'Aberdaran' 'Pots and traps'; ...
'Aberdeen' 'Pots and traps'}
ports = ca(:, 1)
gear = ca(:, 2)
[portGroups, portNames] = findgroups(ports)
[gearGroups, gearNames] = findgroups(gear)
h = histogram2(portGroups, gearGroups)
xticks(unique(portGroups));
yticks(unique(gearGroups));
zticks(1:max(h.BinCounts(:)))
xticklabels(portNames);
yticklabels(gearNames);
xlabel('Port', 'FontSize', fontSize)
ylabel('Gear', 'FontSize', fontSize);
0000 Screenshot.png

1 Comment

Thank you for your help.
I was hoping to extract number comparison, something like:
'Appledoor = 2 pots and traps, 0 Demersal trawl/seine'
'Arbroath = 2 pots and traps, 2 Demersal trawl/seine'
As the dataset is huge!

Sign in to comment.

Asked:

on 13 Jun 2019

Commented:

on 14 Jun 2019

Community Treasure Hunt

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

Start Hunting!