Trying to get a list of the different variables in a column
조회 수: 29 (최근 30일)
이전 댓글 표시
I am trying to create an array which displays the different types of variables i have on one of my columns labelled 'Five' in a table i have. the variables are airport names so i just need to see how many different airports i am collecting different data from. The table is added here to show what i'm working with.
The code i cuurently have is this:
clc
clear all
raw_data = readtable('n10013911.csv');
i = 1;
acronym = zeros(10,1);
for loop = acronym
for index = raw_data(:,'Five')
ii=1
if index == acronym(ii)
ii=ii+1;
else
acronym(i,1) = raw_data(ii,'Five');
i = i + 1;
ii=ii+1;
end
end
end
I'm not the best at for loops and if statements, but this one just doesnt seem to want to work
댓글 수: 0
채택된 답변
Cris LaPierre
2021년 9월 29일
편집: Cris LaPierre
2021년 9월 29일
Five = {'LHR';'LHR';'PEK';'SYD'};
Five = categorical(Five);
categories(Five)
Five = {'LHR';'LHR';'PEK';'SYD'};
unique(Five)
추가 답변 (1개)
Mathieu NOE
2021년 9월 29일
hello
if I understand correctly, you want to extract the list of unique values of the "five" column and store that in an array
you can easily get this by doing :
Five_array = unique(T.Five); % assuming your table is T
댓글 수: 2
Cris LaPierre
2021년 9월 30일
Unique will also work on strings and character arrays, meaning you do not have to convert your data into a categorical first if you use this approach.
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!