I want to read the data columns titled Number and Code. Then use them as a single variable to count how many occurrences of that in total throughout the spreadsheet and write that down in another excel file.

1 ビュー (過去 30 日間)
Both columns I need to read have a collection of numbers and text. Read the Number and Code and then count how many of occurences are there. (There are different Numbers and different Codes for that same Number. (Each row indicates one data set.) Then write that information to a different excel file. For example,
Number Code Count
136-8522 A1 5
136-8522 A2 6
136-8522 B4 10
7398358 B5 15
7398358 G5 10
And so on for each data set.
Excel file is attached.

回答 (1 件)

Githin John
Githin John 2020 年 1 月 20 日
編集済み: Githin John 2020 年 1 月 20 日
Use the xlsread function to read in the raw data. You will see that some of the elements of the number column are numbers and some others string. You can use the cellfun function to convert the 'double' data tyes in the number column to string using the num2str function. Now you have the number column of type string. You can again use a cellfun function to concatenate the number and code values into a single string. Now convert this column of concatenated string values into a categorical table. This will fetch unique number-code pairs and the countcats function will give you the number of occurrences of each number-code pair.
Now the unique function can be used to obtain indices of the unique number-code pairs from the original column. This information of indices can be used to export to an excel file the number value, code, and number of occurences.
function f1=Together(a,b)
function f2=Tostr(c)
if isa(class(c),'double')
elseif ischar(class(c))
  2 件のコメント
Githin John
Githin John 2020 年 1 月 21 日
The categorical will keep track of number of occurences. Use the commands categories(t.W) and countcats(t.W) to get the unique number+code combinations and their occurrences.


Community Treasure Hunt

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

Start Hunting!

Translated by