Identifying variables in an imported csv file

12 views (last 30 days)
Roby George
Roby George on 11 Dec 2020
Commented: dpb on 11 Dec 2020
CALLING ALL MATLAB GENIUSES AND ALSO NEW STARTERS IF YOU KNOW THE ANSWER
I'm doing a project at uni and I've got a problem with a csv file. I've imported it and I've worked out a way to identify the variable in the matrix. All I need to do now is to get the identification process to identify the second variable in that same row as the first one shown, and then display it. I also need it to be able to do calculations with the second variable. Any idea how to do that?
  2 Comments
dpb
dpb on 11 Dec 2020
No idea what you're talking about, sorry...
A .csv file would typically return a 2D array; also typically would be organized wherein columns are variables so simply indexing would return any/all needed.
Show us what you have and what the actual problem seems to be.
dpb
dpb on 11 Dec 2020
As Star-S says, a table would likely be easier to deal with.
As for finding info, w/o knowing what the account ID is (altho apparently you're just using numeric), probably just simply
indx=(find((M:,1)==accountNumber);
is the simplest by far and elminates the loop entirely.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 11 Dec 2020
I have absolutely no idea what you’re describing.
I assume that you have a .csv file with the variable names as the first row, and you want to retrieve them and then do something with that information. To get the variable names at the top of each column, use the readtable function:
T1 = readtable('Your_CSV_File.csv', 'VariableNamingRule','preserve');
then to get the variable names (as a cell array of character vectors):
VarNames = T1.Properties.VariableNames;
The rest of the information are in the columns of ‘T1’ (here).

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!