# I have a .csv file with a list of numbers, what code can I use to check if an inputted number exists in that file.

4 ビュー (過去 30 日間)
Tariq Hammoudeh 2021 年 12 月 2 日
コメント済み: Walter Roberson 2021 年 12 月 2 日
I have a .csv file that contains a list of account numbers. How can i check if an inputted number exists in that file. so for example, I write
AN= 256. What code can I use to check if '256' exists in the .csv file or not.

サインインしてコメントする。

### 回答 (1 件)

Walter Roberson 2021 年 12 月 2 日
readtable(). ismember() the appropriate column of the table.
##### 2 件のコメント表示非表示 1 件の古いコメント
Walter Roberson 2021 年 12 月 2 日
No, there is no MATLAB function that you can pass in a file name and a value and get back the response Yes the value exists in the file or No it does not exist in the file.
You need to read the data in and test the values once they are in memory.
help ismember
ISMEMBER True for set member. LIA = ISMEMBER(A,B) for arrays A and B returns an array of the same size as A containing true where the elements of A are in B and false otherwise. LIA = ISMEMBER(A,B,'rows') for matrices A and B with the same number of columns, returns a vector containing true where the rows of A are also rows of B and false otherwise. [LIA,LOCB] = ISMEMBER(A,B) also returns an array LOCB containing the lowest absolute index in B for each element in A which is a member of B and 0 if there is no such index. [LIA,LOCB] = ISMEMBER(A,B,'rows') also returns a vector LOCB containing the lowest absolute index in B for each row in A which is a member of B and 0 if there is no such index. The behavior of ISMEMBER has changed. This includes: - occurrence of indices in LOCB switched from highest to lowest - tighter restrictions on combinations of classes If this change in behavior has adversely affected your code, you may preserve the previous behavior with: [LIA,LOCB] = ISMEMBER(A,B,'legacy') [LIA,LOCB] = ISMEMBER(A,B,'rows','legacy') Examples: a = [9 9 8 8 7 7 7 6 6 6 5 5 4 4 2 1 1 1] b = [1 1 1 3 3 3 3 3 4 4 4 4 4 9 9 9] [lia1,locb1] = ismember(a,b) % returns lia1 = [1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1] locb1 = [14 14 0 0 0 0 0 0 0 0 0 0 9 9 0 1 1 1] [lia,locb] = ismember([1 NaN 2 3],[3 4 NaN 1]) % NaNs compare as not equal, so this returns lia = [1 0 0 1], locb = [4 0 0 1] Class support for inputs A and B, where A and B must be of the same class unless stated otherwise: - logical, char, all numeric classes (may combine with double arrays) - cell arrays of strings (may combine with char arrays) -- 'rows' option is not supported for cell arrays - objects with methods SORT (SORTROWS for the 'rows' option), EQ and NE -- including heterogeneous arrays derived from the same root class See also ISMEMBERTOL, INTERSECT, UNION, UNIQUE, UNIQUETOL, SETDIFF, SETXOR, SORT, SORTROWS. Documentation for ismember doc ismember Other functions named ismember categorical/ismember mtree/ismember cell/ismember nominal/ismember dataset/ismember sym/ismember datetime/ismember tabular/ismember duration/ismember tall/ismember gpuArray/ismember textanalytics.internal.wordlist/ismember

サインインしてコメントする。

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by